akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int ok[] = {5,7,5,7,7};

int main()
{	
	int n;
	
	while(cin >> n,n)
	{
		vector<string> v;
		REP(i,n)
		{
			string tmp;cin >> tmp;
			v.PB(tmp);
		}
		
		REP(i,n)
		{
			int cou = 0;
			int num = 0;
			for(int j = i;j < n;j++)
			{
				num += v[j].size();
				if(num == ok[cou])
				{
					cou++;
					num=0;
					if(cou == 5)
					{
						cout << i+1 << endl;
						goto NEXT;
					}
					
				}
				else if(num > ok[cou])
				{
					break;
				}
			}
		}
		NEXT:;
	}
			
			
	return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;
using ll = long long;

int main(){
    int N,X,T;
    cin >> N >> X >> T;
    int turn;
    turn = N / X;
    if(N%X!=0){
        cout << (turn+1) * T << endl;
    }
    else{
        cout << turn * T << endl;
    }
    return 0;
}

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

using namespace std;

int n;

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

    cin >> n;

    n = n % 10;
    if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
        cout << "hon";
    else if(n == 0 || n == 1 || n == 6 || n == 8)
        cout << "pon";
    else
        cout << "bon";

    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

int n;
ll a, b;
vll vx;
vll dp;
const ll INF = 10e15;

void init()
{
	cin >> n >> a >> b;
	vx.resize(n);
	REP(i, n)
		cin >> vx[i];
	sort(ALL(vx));
	dp.resize(n, INF);
	dp[0] = 0;
}

int main()
{
	init();

	REP1O(i, n)
	{
		dp[i] = min(dp[i - 1] + a * (vx[i] - vx[i - 1]), dp[i - 1] + b);
	}

	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			HashMap<String, Long> map = new HashMap<String, Long>(); 
			
			for(int i = 0; i < N; i++) {
				final char[] chs = sc.next().toCharArray();
				Arrays.sort(chs);
				
				final String str = String.valueOf(chs);
				
				if(!map.containsKey(str)) { map.put(str, 0l); }
				map.put(str, map.get(str) + 1);
			}
			
			long sum = 0;
			for(final long val : map.values()) { sum += (val * (val - 1)) / 2; }
			System.out.println(sum);
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 46344
// AtCoder Beginner Contest 121 - Problem C: Energy Drink Collector (https://atcoder.jp/contests/abc121/tasks/abc121_c)
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

ll solve(ll M, vector<ii>& ds)
{
    sort(ds.begin(), ds.end());

    ll ans = 0, left = M;

    for (size_t i = 0; i < ds.size(); ++i)
    {
        auto A = ds[i].first;
        auto B = ds[i].second;

        ll qtd = min(left, B);

        ans += A*qtd;
        left -= qtd;

        if (left == 0)
            break;
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;

    vector<ii> ds(N);

    for (int i = 0; i < N; ++i)
        cin >> ds[i].first >> ds[i].second;

    auto ans = solve(M, ds);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,x,y,ans=1,mod=1e9 + 7;
string s;
int main(){
	cin >> n >> s;
    for(ll i=2*n-1;i>=0;i--)
        if((i%2==0 and s[i]=='W')or(i%2==1 and s[i]=='B'))x++;
        else (ans*=x)%=mod,x--,y++;
    for(ll i=2;i<=n;i++)
        (ans*=i)%=mod;
    printf("%d",y==n?ans:0);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>

using namespace std;

bool intension(set<int>& s1, set<int>& s2) {
	if (s1.size() < s2.size()) {
		return false;
	}

	for (set<int>::iterator itr = s2.begin(); itr != s2.end(); ++itr) {
		if ((s1.find(*itr)) == s1.end()) {
			return false;
		}
	}
	return true;
}

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

	while (N != 0) {
		vector< set<int> > data(N+1);
		int cri = -1;
		int count = 0;
		int temp;
		int M;
		for (int i = 0; i < N+1; ++i) {
			cin >> M;
			for (int j = 0; j < M; ++j) { 
				cin >> temp;
				data[i].insert(temp);
			}
			
		}

		for (int i = 0; i < N; ++i) {
			if (count < 2) {
				if (intension(data[i], data[N])) {
					cri = i+1;
					++count;
				}
			}
		}
		if (count > 1) {
			cout << -1 << endl;
		}
		else {
			cout << cri << endl;
		}

		cin >> N;
	}

	return 0;
}

Measured memory_bytes: 3408
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll N;

cin >> N;

N = N%10;

if(N == 3) cout << "bon" << endl;
else if(N == 0 or N == 1 or N == 6 or N == 8) cout << "pon" << endl;
else cout << "hon" << endl;

return 0;

}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(c + " " + a + " " + b);
    }
}


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

typedef long long ll;
typedef pair<int,int> p_int;
typedef pair<ll,ll> p_ll;
typedef tuple<ll,ll,ll> t3_ll;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
const ll inf = 1000000007;

int main() {
	ll n,W;
	cin >> n >> W;
	ll w[n],v[n];
	for (int i = 0;i < n;i++) {
		cin >> w[i] >> v[i];
	}
	ll dp[100050];
	for (int i = 0;i < 100050;i++) {dp[i] = 1145141919810;}
	dp[0] = 0;
	for (int i = 0;i < n;i++) {
		for (int j = 100000;j >= v[i];j--) {
			dp[j] = min(dp[j],dp[j-v[i]]+w[i]);
		}
	}
	ll ans = 0;
	for (int i = 0;i < 100001;i++) {
		if (dp[i] <= W) ans = i;
	}
	cout << ans << endl;
}

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

h, w = [int(x) for x in input().split()]
a = []
for _ in range(h):
    a.append([int(x) for x in input().split()])
ans = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if j == w - 1 and i != h - 1:
                if a[i][j] % 2 == 1:
                    a[i + 1][j] += 1
                    ans.append([i + 1, j + 1, i + 2, j + 1])
            elif a[i][j] % 2 == 1 and j != w - 1:
                a[i][j + 1] += 1
                ans.append([i + 1, j + 1, i + 1, j + 2])
    else:
        for j in range(w - 1, -1, -1):
            if j == 0 and i != h - 1:
                if a[i][j] % 2 == 1:
                    a[i + 1][j] += 1
                    ans.append([i + 1, j + 1, i + 2, j + 1])
            elif a[i][j] % 2 == 1 and j != 0:
                a[i][j - 1] += 1
                ans.append([i + 1, j + 1, i + 1, j])
print(len(ans))
for i in ans:
    print(*i)
            


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

int arr[5],mn=INT_MAX;
bool v[5];
int order(int pos, int sum, int cnt, bool visited[5]){
	if(cnt==5){
		if(sum<mn)
			mn=sum;
	}
	for(int i=0;i<5;i++){
		if(!visited[i]){
			if(sum%10==0){
				visited[i]=true;
				order(pos+1, sum+arr[i], cnt+1, visited);
				visited[i]=false;
			}
			else{
				visited[i]=true;
				order(pos+1, sum+10-(sum%10)+arr[i], cnt+1, visited);
				visited[i]=false;
			}
		}
	}
	return mn;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	memset(v, false, 5);
	for(int i=0;i<5;i++){
		cin>>arr[i];
	}
	cout<<order(0,0,0,v);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int grp[2][200003];
vector<int> edge[2][200003];
int ans[200003];
vector<pair<pair<int, int>, int>> t;

void func(int s, int pos, int g) {
	grp[s][pos] = g;
	for (int i = 0; i < (int)edge[s][pos].size(); ++i) {
		if (grp[s][edge[s][pos][i]] != 0) continue;
		func(s, edge[s][pos][i], g);
	}
}


int main() {
	int n, k, l; cin >> n >> k >> l;
	for (int i = 0; i < k; ++i) {
		int u, v; cin >> u >> v;
		--u; --v;
		edge[0][u].push_back(v);
		edge[0][v].push_back(u);
	}
	for (int i = 0; i < l; ++i) {
		int u, v; cin >> u >> v;
		--u; --v;
		edge[1][u].push_back(v);
		edge[1][v].push_back(u);
	}
	for (int s = 0; s < 2; ++s) {
		int cnt = 0;
		for (int i = 0; i < n; ++i) {
			if (grp[s][i] != 0) continue;
			func(s, i, ++cnt);
		}
	}

	for (int i = 0; i < n; ++i) t.push_back({ {grp[0][i], grp[1][i] }, i });
	sort(t.begin(), t.end());

	int g = 0;
	for (int i = 0; i < n; ++i) {
		int cnt = 0;
		for (int j = i; j < n; ++j) {
			if (t[i].first.first == t[j].first.first && t[i].first.second == t[j].first.second) ++cnt;
			else break;
		}
		for (int j = i; j < n; ++j) {
			if (t[i].first.first == t[j].first.first && t[i].first.second == t[j].first.second) ans[t[j].second] = cnt;
			else break;
		}
		i += cnt - 1;
		++g;
	}

	for (int i = 0; i < n; ++i) {
		if (i > 0) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

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

int main () {
  int a , b , c , N , ans = 0 ;
  cin >> a >> b >> c >> N ;
  for(int i = 0 ; i <= a ; i++ ){
    for(int j = 0 ; j <= b ; j++ ){
      for(int k = 0 ; k <= c ; k++ ){
        if( 500 * i + 100 * j + 50 * k == N ) ans++ ;
      }
    }
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<deque>
using namespace std;
int ans[300005];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    int x;
    scanf("%d",&x);
    //cout<<(n-i)/2<<" "<<n-(n-i)/2<<endl;
    if(i%2==0){
    if(n%2==0)
    ans[1+(n-i)/2]=x;
    else
    ans[n-(n-i)/2]=x;
    }
    else{
    if(n%2==0)
    ans[n-(n-i)/2]=x;
    else
    ans[1+(n-i)/2]=x;     
    }
    }
    for(int i=1;i<=n;i++)printf("%d ",ans[i]);
    //system("pause");
    return 0;
}


Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main()
{
	int N;
	cin>>N;
	int *numArray = new int[N];
	for(int i = 0; i < N; i++){
		cin>>numArray[i];
	}
	sort(numArray,numArray + N);
	/*for(int i = 0; i < N; i++){
		cout<<numArray[i]<<" ";
	}*/
	bool isItSame = false;
	if(numArray[0] == numArray[1]){
		isItSame = true;
	}
	for(int i = 1; i < N-1; i++){
		if( numArray[i] == numArray[i-1] || numArray[i] == numArray[i+1]){
			isItSame = true;
			break;
		}
	}
	if(numArray[N-2] == numArray[N-1]){
		isItSame = true;
	}
	if(isItSame == true){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n*3];
  for(int i=0; i<n*3; ++i) cin >> a[i];
  sort(a, a+(n*3), greater<int>());
  long long ans = 0;
  for(int i=1; i<n*2; i+=2) ans += a[i];
  cout << ans << endl;
}

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

#define endl '\n'

using namespace std;

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

    int n, arr[100], cnt = 0;
    cin >> n;
    for(size_t i = 0; i < n; i++) cin >> arr[i];

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n - 1 - i; j++)
        {
            if(arr[j] > arr[j + 1])
            {
                cnt++;
                swap(arr[j], arr[j + 1]);
            }
        }
    }

    for(size_t i = 0; i < n; i++)
    {
        cout << arr[i];
        if(i < n - 1) cout << " ";
    }
    cout << endl << cnt << endl;

    return 0;
}



Measured memory_bytes: 3176
import java.util.*

fun Char.toReverseCase() =
    if (this.isUpperCase()) this.toLowerCase() else this.toUpperCase()

fun String.toReverseCase() =
    String(this.toCharArray().map { it.toReverseCase() }.toCharArray())

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val s = scanner.nextLine()
    println(s.toReverseCase())
}



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

int main(){
  int n,N;
  string suit;
  int card[4][13] = {0};
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> suit >> N;
    if(suit == "S") card[0][N-1] = 1;
    if(suit == "H") card[1][N-1] = 1;
    if(suit == "C") card[2][N-1] = 1;
    if(suit == "D") card[3][N-1] = 1;
  }
  string str[4] = {"S","H","C","D"};
  for(int i =0;i < 4;i++){
    for(int j =0;j < 13;j++){
      if(card[i][j] == 0)
	cout<< str[i] << ' ' << j + 1 << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3112
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int k=scan.nextInt();
        int ans=1;
        for(int i=0;i<n-1;i++){
            ans*=(k-1);
        }
        System.out.println(ans*k);


    }
}

Measured memory_bytes: 9680
#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

string a;
ll ra[128];

void init(){
  a = "";
  for(int i = 0; i < 10; i++){
    a += (char)('0' + i);
    ra['0' + i] = a.size() - 1;
  }
  for(int i = 0; i < 26; i++){
    a += (char)('A' + i);
    ra['A' + i] = a.size() - 1;
  }
  for(int i = 0; i < 26; i++){
    a += (char)('a' + i);
    ra['a' + i] = a.size() - 1;
  }
}

ll toLL(ll p, string m){
  ll res = 0;
  for(int i = 0; i < m.size(); i++){
    res *= p;
    res += ra[m[i]];
  }
  return res;
}

void nim(ll x, ll &calc){
  string tmp;

  for(ll i = 0; (1LL << i) <= x; i++){
    if(x & (1LL << i)){
      tmp += "1";
    }
    else{
      tmp += "0";
    }
  }

  for(ll i = 0; i < tmp.size(); i++){
    if(tmp[i] == '0') continue;

    ll j;
    for(j = i; j < tmp.size() && tmp[j] == '1'; j++);

    calc ^= j - i;
    i = j;
  }
}

int main(){
  init();

  int n;

  while(cin >> n){
    ll calc = 0;

    for(int i = 0; i < n; i++){
      ll p;
      string m;
      cin >> p >> m;

      ll x = toLL(p, m);
      nim(x, calc);
    }

    cout << (0 < calc ? "win" : "lose") << endl;
  }
}

Measured memory_bytes: 1212
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    char c[3];
    cin >> c;
    int count = 0;
    for(int i=0;i<3;i++){
        if(c[i] == '1')
            count++;
    }
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
struct edge{
  int a,b,c;
  bool operator<(const edge &e) const{
    return c < e.c;
  }
};
typedef long long ll;
 
struct uni{
  int d[100003];
  int f[100003];
  void init(){ memset(d,-1,sizeof(d)); memset(f,0,sizeof(f)); }
  int find(int a){ return d[a]<0?a:(d[a]=find(d[a])); }
  void marge(int a,int b){
    a = find(a); b = find(b);
    if( a == b ) return ;
    if( d[a] > d[b] ) swap(a,b);
    if( f[a] || f[b] ) f[a] = 1;
    d[a]+=d[b]; d[b] = a;
  }
  bool same(int a,int b){
    return find(a) == find(b);
  }
  int size(int a){
    return -d[find(a)];
  }
  bool isbase(int a){ return f[find(a)]; }
};
 
int N,T,K;
uni U;
 
int main(){
  int ttt =0;
  while( cin >> N >> T >> K && (N||T||K) ){
 
    U.init();
    ll sum = 0;
    vector<edge> E;
    vector<edge> E2;
    for(int i=0;i<N-1;i++){
      int a,b,c;
      cin >> a >> b >> c;
      E.push_back( (edge){a,b,c} );
      sum += c;
    }
    for(int i=0;i<T;i++){
      int a; cin >> a;
      U.f[a] = 1;
    }
    for(int i=0;i<N-1;i++){
      if( !U.isbase(E[i].a) || !U.isbase(E[i].b) ) E2.push_back(E[i]);
    }
    ll res = 0;
    sort(E2.rbegin(),E2.rend());
    int ks = 0;
    for(int i=0;i<(int)E2.size();i++){
      int a = E2[i].a, b = E2[i].b, c = E2[i].c;
      if( U.same(a,b) ) continue;
      if( !U.isbase(a) || !U.isbase(b) ){
    U.marge(a,b);
    res += (ll)c;
    ks++;
      }
    }
    //  cout << ks << endl;
    //cout << N-K-1 << endl;
    assert(N-K-1>=ks);
    sort(E.rbegin(),E.rend());
    for(int i=0;N-K-1>ks;i++){
      if( U.same(E[i].a,E[i].b) ) continue;
      U.marge(E[i].a,E[i].b);
      res += (ll)E[i].c;
      ks++;
    }
    // cout << N - K - 1<< endl;
    //cout << ks << endl;
    cout << "Case " << ++ttt << ": " << sum - res << endl;
  }
}

Measured memory_bytes: 2388
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    k=parseInt(readline())
    seven_mod_k=0
    ans=-1
    for i in 1:k
        seven_mod_k=(seven_mod_k*10+7)%k
        if seven_mod_k==0
            ans=i
            break
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 157952
#include <stdio.h>

int main() {
  int N;
  scanf("%d",&N);
  if(N<=999) {
    N = N%10%10;
    if(N==3) {
      printf("bon");
    }else if(N==0 || N==1 || N==6 || N==8) {
      printf("pon");
    }else {
      printf("hon");
    }
  }
  return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
#define max 100000
using namespace std;
ll l = 1000000007;

ll x[100050] = {};
ll ans[100050] = {};
int main()
{
	ll n, m;
	ll res = 0;
	cin >> n >> m;

	for (ll i = 0; i < m; i++)
	{
		cin >> x[i];
	}

	sort(x, x + m);
	
	for (ll i = 0; i < m - 1; i++)
	{
		ans[i] = x[i + 1] - x[i];
	}

	sort(ans, ans + (m - 1));

	for (ll i = 0; i < (m - 1) - (n - 1); i++)
	{
		res += ans[i];
	}

	cout << res;
}



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

const int INF = 1001001001;

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i,n) {
      cin >> c[i];
      rep(j,m) cin >> a[i][j];
  }
  
  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize, k: usize,
        pv: [Usize1; n],
        cv: [i64; n],
    };

    let mut res: i64 = -(1_i64 << 60);
    for i in 0..n {
        let mut step = Vec::new();
        let mut loop_sum = 0;
        let mut j = pv[i];
        loop {
            loop_sum += cv[j];
            step.push(cv[j]);
            if i == j {
                break;
            }
            j = pv[j];
        }

        let no_loop_score = {
            let mut max = step[0];
            let mut cur = step[0];
            for k in 1..std::cmp::min(k, step.len()) {
                cur += step[k];
                if cur > max {
                    max = cur;
                }
            }
            max
        };

        let loop_count = if k >= step.len() {
            (k - step.len()) / step.len()
        } else {
            0
        };
        let loop_score = loop_sum * loop_count as i64;
        let rest_step = k - loop_count * step.len();
        let score = if loop_count == 0 {
            let mut max = step[0];
            let mut cur = step[0];
            for k in 1..rest_step {
                cur += step[k % step.len()];
                if cur > max {
                    max = cur;
                }
            }
            max
        } else {
            let mut max = 0;
            let mut cur = 0;
            for k in 0..rest_step {
                cur += step[k % step.len()];
                if cur > max {
                    max = cur;
                }
            }
            std::cmp::max(no_loop_score, loop_score + max)
        };
        if score > res {
            res = score;
        }
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2440
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	//------------------------------------------



	public void exec() throws Exception{
		final int N = sc.nextInt();
		final int[] X = new int[N];
		int sum = 0;
		for(int i=0;i<N;i++) {
			X[i] = sc.nextInt();
			sum += X[i];
		}

		int mid1 = sum / N;
		int mid2 = mid1 + 1;

		int cost1 = 0;
		int cost2 = 0;
		for(int i=0;i<N;i++) {
			cost1 += (X[i] - mid1)*(X[i] - mid1);
			cost2 += (X[i] - mid2)*(X[i] - mid2);
		}

		out.println(Math.min(cost1, cost2));

	}
}


Measured memory_bytes: 22996
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define MOD 1000000007
using namespace std;
char board[52][52];
int x[8] = {1,-1,0,0,-1,1,-1,1};
int y[8] = {0,0,1,-1,1,-1,-1,1};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    cin >> H >> W;
    for(int i = 1; i <= H; i++){
        for(int l = 1; l <= W; l++){
            cin >> board[i][l];
        }
    }
    for(int i = 1; i <= H; i++){
        for(int l = 1; l <= W; l++){
            if(board[i][l]=='#'){
                cout << "#";
            }else{
                int ans = 0;
                for(int w = 0; w < 8; w++){
                    if(board[i+x[w]][l+y[w]]=='#'){
                        ans++;
                    }
                }
                cout << ans;
            }
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class AConnectionAndDisconnection {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            int k = in.nextInt();
            int from = -1;
            int to = s.length();
            for (int i = 1; i < s.length(); i++) {
                if (s.charAt(i) != s.charAt(0)) {
                    from = i;
                    break;
                }
            }
            if (from == -1) {
                long ans = 1L * s.length() * k / 2;
                out.println(ans);
                return;
            }
            for (int i = 1; i < s.length(); i++) {
                if (s.charAt(i) != s.charAt(0)) {
                    to = i + 1;
                }
            }
            long ans = 0;
            for (int i = from; i < to; i++) {
                if (i < s.length() && s.charAt(i) == s.charAt(i - 1)) {
                    ans += k;
                    i++;
                }
            }
            int pref = from;
            int suff = (s.length() - to);
            ans += pref / 2;
            ans += suff / 2;
            ans += 1L * (pref + suff) / 2 * (k - 1);


            out.println(ans);
        }

    }
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
 
 
int main(){
    
  ll n ,y;
  cin >> n >> y;
  int total;
  for(int i= 0;i<=n;++i){
    for(int j = 0;j<=n-i;++j){
      for(int k = 0; k<=n-i-j;++k){
      total = 10000*i+5000*j+k*1000;
      if (total == y && i+j+k ==n)  {cout << i << ' ' << j << ' ' << k << endl;
      return 0;
    }
    }
  }
  }
  cout << -1 << ' ' << -1<<' ' <<-1 << endl;
  return 0;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

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

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

    int mn = 1000000000;
    for (int i = -100; i <= 100; i++) {
        int t = 0;
        for (int j = 0; j < n; j++) {
            t += (a[j] - i) * (a[j] - i);
        }
        mn = min(mn, t);
    }
    cout << mn << endl;
}


Measured memory_bytes: 256
#include <iostream>

int bubbleSort(int * A, int N) {
    int count = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int i = N - 1; i > 0 ; i--) {
            if (A[i] < A[i - 1]) {
                std::swap(A[i], A[i - 1]);
                flag = true;
                count++;
            }
        }
    }
    return count;
}

void printSort(int * A, int N) {
    for (int i = 0; i < N - 1; i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A[N - 1] << std::endl;
}

int main() {
    int N;
    std::cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    int count = bubbleSort(A, N);
    printSort(A, N);
    std::cout << count << std::endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; for(auto s:S) os<<s<<" ";return os<<"}"; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) { os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}"; }
#ifdef LMAO
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | "; __f(comma+1, args...); }
#else
    #define trace(...) 42
#endif
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
#define all(x) x.begin(), x.end()
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAX = 1000010;
const int MOD2 = 998244353;
const int MOD = 1000000007; 
const int INF = 1e8;    
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ld EPS = 1e-7;
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)   
/*****************start************/
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout<<fixed<<setprecision(25);cerr<<fixed<<setprecision(10);
    auto start = std::chrono::high_resolution_clock::now();
    string s,t;
    int ans=0;
    cin>>s>>t;
    for(int i=0;i<s.size();i++)
        ans+=(s[i]!=t[i]);
    cout<<ans<<endl;
    auto stop = std::chrono::high_resolution_clock::now(); 
    auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); 
    // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< endl;     
    return 0;
}


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

const int N = 100;
int m[N][N];

int main()
{

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int u, k; // k == 出次数
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++)
		{
			int v;
			cin >> v;
			v--;
			m[u][v] = 1;
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (j) cout << " ";
			cout << m[i][j];
		}
		cout << endl;
	}

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch MatchMatching | diff MatchMatching.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address MatchMatching.cpp && ./a.out

/*
 
 2/28/2019
 
 15:42-16:46 WA
 17:00 give up
 
 */

LL cost[10]={0,2,5,5,4,5,6,3,7,6};

const int MAX_N=1e4+1;
int A[10];
int N,M;

int to[10][MAX_N];
int dp[10][MAX_N];
VI ds;
const int Inf=1e5;
void solve() {
  REP(i,M)ds.push_back(A[i]);
  sort(ds.rbegin(),ds.rend());
  MINUS(to);
  REP(i,10)REP(j,MAX_N) dp[i][j]=-Inf;
  dp[M][0]=0;
  for(int j=M-1; j>=0; --j) REPE(i,N) {
    int d=ds[j],c=cost[d];
    for(int k=i/c; k>=0; --k) {
      if(i-k*c<0) dump(j,i,d,c,k,k*c);
      int ii=i-k*c;
      assert(ii>=0);
      if(dp[j+1][ii]>=0&&dp[j+1][ii]+k>dp[j][i]) {
        dp[j][i]=dp[j+1][ii]+k;
        to[j][i]=k;
      }
    }
  }
  string res;
  int i=N;
  REP(j,M) {
    int cnt=to[j][i];
    assert(cnt>=0);
    int d=ds[j];
    string s(cnt,'0'+d);
    res+=s;
    i=i-cnt*cost[d];
  }
  assert(i==0);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,M) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 1024
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18



def main():
    N = int(stdin.readline().rstrip())
    A = list(map(int, stdin.readline().rstrip().split()))
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    big = gcd(A[0],A[1])
    for i in range(2,N):
        big = gcd(big,A[i])
    print(big)

main()


Measured memory_bytes: 16324
#include<stdio.h>

int main(){
	int i,j,m,s,y,n,f,k,maxs,ts,tb,e;
	double p;
	scanf("%d",&m);
	while(m--){
		scanf("%d",&s);
		scanf("%d",&y);
		scanf("%d",&n);
		maxs=0;
		for(i=0;i<n;i++){
			ts=0;
			tb=0;
			e=0;
			scanf("%d %lf %d",&f,&p,&k);
			if(f){ //bi
				for(tb=s,j=0;j<y;j++){
					tb=tb*(1.0+p)-k;			
				}				
				if(tb>maxs)maxs=tb;
			}else{ //single
				for(ts=s,j=0;j<y;j++){
					e+=ts*p;
					ts-=k;
				}
				if(ts+e>maxs)maxs=ts+e;
			}
		}
		printf("%d\n",maxs);
	}
	return 0;
}

Measured memory_bytes: 1060
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	long long N, M;
	cin >> N >> M;

	if(N > M)
		swap(N, M);

	long long ret = 0;
	if(N == 1){
		if(M == 1)
			ret = 1;
		else
			ret = M - 2;
	}
	else
		ret = (N-2) * (M-2);

	cout << ret << endl;

	return 0;
}


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

int main()
{
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    cout << w*h/2 << endl;
    if(x == w/2 && y == h/2){
        cout << 1 << endl;
    }else{
        
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;
    Set<String> set = new HashSet<>();
    int K;

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

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] array = sc.next().toCharArray();
        StringBuilder str = new StringBuilder();

        int firstA = -1;
        int lastZ = -1;

        for(int i=0; i<array.length; i++){
            String s = String.valueOf(array[i]);
            if(s.equals("A") && firstA == -1) firstA = i;
            if(s.equals("Z")) lastZ = i;
        }

        for(int i=firstA; i<=lastZ; i++){
            str.append(String.valueOf(array[i]));
        }

        System.out.println(str.length());
    }

    double manhattan(Ten point1, Ten point2){
        return Math.abs(point1.getX() - point2.getX()) + Math.abs(point1.getY() - point2.getY());
    }

    void substring(String s, int num){
        for(int i=1; i<=num; i++){
            if(i > K){
                break;
            }
            for(int j=0; j<num; j++){
                if(j + i-1 < num){
//                    System.out.println(s.substring(j, j+i));
                    set.add(s.substring(j, j+i));
                } else {
                    break;
                }
            }
        }
    }

    void permutation(String s, String ans){
        if(s.length() <= 1){
            System.out.println(ans + s);
        } else {
            for(int i=0; i<s.length(); i++){
                permutation(s.substring(0, i) + s.substring(i + 1), ans + s.charAt(i));
            }
        }
    }
}

class Ten{
    private int x;
    private int y;

    Ten(int x, int y){
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}

Measured memory_bytes: 40156
fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let m = v[1];
    let a = read_vec::<u64>();

    let a_half = a.into_iter().map(|ai| ai / 2).collect::<Vec<_>>();
    let mut a_gcd = a_half[0];
    for i in 1..n as usize {
        a_gcd = gcd(a_gcd, a_half[i]);
    }

    let a2 = a_half.into_iter().map(|ai| ai / a_gcd).collect::<Vec<_>>();
    let mut a_lcm = 1;
    for ai in a2 {
        if ai % 2 == 0 {
            println!("0");
            return;
        } else {
            a_lcm = lcm(a_lcm, ai);
        }
    }
    let aa = a_gcd * a_lcm;
    let ans = if (m / aa) % 2 == 0 {
        m / (aa * 2)
    } else {
        m / (aa * 2) + 1
    };
    println!("{}", ans);
}

fn gcd(x: u64, y: u64) -> u64 {
    if x == 0 {
        y
    } else {
        gcd(y % x, x)
    }
}

fn lcm(x: u64, y: u64) -> u64 {
    x * y / gcd(x, y)
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8444
# include<iostream>

using namespace std;
int main(){
	int R0,W0,C,R,X,Y,countY;
	while(1){
		cin >> R0 >> W0 >>C >>R;
		
		countY=0;
		if(R0==0&&W0==0&&C==0&&R==0){
			break;
		}
		X=0;
		Y=0;
		while(1){
			if(R0/W0<C){
				
				while(1){
					if((R0+X*R)/W0 >= C){
						R0=R0+X*R;
						break;
					}
					X++;
				}
			}
			else if(R0/W0>C){
				
				while(1){
					if(R0/(W0+Y)<= C){
						W0=W0+Y;
						break;
					}
					Y++;
				}
			}
			else if(R0/W0==C){
				break;
			}
		}
		cout << X <<endl;
		
	}
	return 0;
}



Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int dp[200010][3], pre[200010][3];
int main() {
    string s; cin >> s;

    // int N = s.size();
    // fill(dp[0], dp[N+1], -INF);
    // dp[0][2] = 0;
    // for(int i=0; i<N; i++) {
    //     for(int j=0; j<3; j++) {
    //         // 'P', 'D'
    //         for(int k=0; k<2; k++) {
    //             char c = (k == 0 ? 'P' : 'D');
    //             if(k == 0 and s[i] == 'D') continue;
    //             if(k == 1 and s[i] == 'P') continue;
    //             // P なら何も起こらない

    //             // D なら前が P のとき +2, そうでないなら +1
                
    //         }
    //     }
    // }

    for(auto &c : s) if(c == '?') c = 'D';
    cout << s << endl;
    return 0;
}


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

int card[255][14] = {{0}};
 
int main(void){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        char c;
        int num;
        cin >> c >> num;
        card[(int)c][num] = 1;
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'S'][i] == 0){
            cout << "S" << " " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'H'][i] == 0){
            cout << "H" << " " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'C'][i] == 0){
            cout << "C" << " " << i << endl;
        }
    }
    for(int i = 1; i <= 13; i++){
        if(card[(int)'D'][i] == 0){
            cout << "D" << " " << i << endl;
        }
    }
}



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

int main() {
  string S;
  cin >> S;
  int y, m, d;
  y = (S.at(0) - '0')*1000 + (S.at(1) - '0')*100 + (S.at(2) - '0')*10 + S.at(3) - '0';
  m = (S.at(5) - '0')*10 + S.at(6) - '0';
  d = S.at(8) - '0' + S.at(9) - '0';
  if (y*2000 + m*100 + d > 4038430) {
    cout << "TBD" << endl;
  }
  else {
    cout << "Heisei" << endl;
  }
}

Measured memory_bytes: 256