akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>
#include<stack>
#include<fstream>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> lltpl;
typedef tuple<int, int, int> tpl;

int dy8[8] = { 2,2,-2,-2,1,1,-1,-1 };
int dx8[8] = { 1,-1,1,-1,2,-2,2,-2 };
int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };


/******************************************************************************************/

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

// vector
template <typename T>
istream& operator>>(istream & is, vector<T> & vec) { for (T& x : vec) is >> x; return is; }
// pair
template <typename T, typename U>ostream& operator<<(ostream & os, pair<T, U> & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; }
// vector
template <typename T>ostream& operator<<(ostream & os, const vector<T> & vec) { os << "{";	for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; }
// map
template <typename T, typename U>ostream& operator<<(ostream & os, map<T, U> & map_var) { os << "{";	repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; }
// set
template <typename T>ostream& operator<<(ostream & os, set<T> & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; }



const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
constexpr ll MOD = 1e9 + 7;

//ここから書くこと




ll dp[3005];

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n, t;
	cin >> n >> t;
	vector<pii> a(n), b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());

	

	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = t - 1; j >= 0; j--)
		{
			dp[j] = max(dp[j], dp[j]);
			dp[min(j + a[i].first,t)] = max(dp[min(j + a[i].first,t)], dp[j] + a[i].second);
		}
	}

	ll maxi = 0;

	for (int i = 0; i < 3005; i++)
	{
		maxi = max(maxi, dp[i]);
	}
	cout << maxi << endl;


	return 0;
}


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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	if (n % 2 == 1)
		cout << "No\n";
	else {
		for (int i = 0; i < n / 2; i++) {
			if (s[i] != s[i + n / 2]) {
				cout << "No\n"; break;
			}
			if (i == n / 2 - 1)
				cout << "Yes\n";
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

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

int main() {
    ll N;
    cin >> N;
    ll ans = N - 1;
    for (ll i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, A;
int main() {
 int A, B, C, D;
  cin >> A >> B >> C >> D;
  int E = A + B;
  int F = C + D;
 if(E > F){
   cout << "Left" << endl;
 }
 else if(E < F){
    cout << "Right" << endl;
  }
 else{
   cout << "Balanced" << endl;
 }
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;

int f(int n){
    int s = 0;
    for(int i = 1; i * i < n; i++){
        if(n % i == 0){
            s += 2;
        }
    }
    int k = int(sqrt(n));
    if(k * k == n)
        s++;
    return s;
}

int main()
{
    _FastIO;
    cin >> n;
    int s = 0;
    for(int i = 1; i <= n; i += 2){
        if(f(i) == 8)
            s++;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3628
#14:10
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  if i == 0:
    b.append(a[i])
  else:
    big = b[-1]
    sml = a[i]
    while sml != 0:
      big,sml = sml,big%sml
    b.append(big)
c = []
for j in range(n)[::-1]:
  if j == n-1:
    c.append(a[j])
  else:
    big = c[-1]
    sml = a[j]
    while sml != 0:
      big,sml = sml,big%sml
    c.append(big)
c.reverse()
d = []
for i in range(n):
  if i == 0:
    d.append(c[1])
  elif i == n-1:
    d.append(b[n-2])
  else:
    big = b[i-1]
    sml = c[i+1]
    while sml != 0:
      big,sml = sml,big%sml
    d.append(big)
#print(b)
#print(c)
#print(d)
print(max(d))

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

int main ()
{
    int num[10001];
    for (int i = 1; i <= 1000; i++) {
        num[i] = num[i-1] + i;
    }

    int n;
    while (cin >> n, n) {
        int i = 0, j = 0, res = 0;;
        while (j <= (n + 1) / 2) {
            if (num[j] - num[i] < n) {
                j++;
            } else if (num[j] - num[i] == n && j - i >= 2) {
                res++;
                i++;
            } else {
                i++;
            }
        }

        cout << res << endl;
    }

    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n, m;
map<pii, vector<pii> > g;
map<int, int> d[112345];

int main() {
	cin >> n >> m;
	REP(i, m) {
		int p, q, c;
		scanf("%d %d %d", &p, &q, &c);
		p--; q--;
		g[pii(p, c)].push_back(pii(q, c));
		g[pii(q, c)].push_back(pii(p, c));
		
		g[pii(p, 0)].push_back(pii(q, c));
		g[pii(q, 0)].push_back(pii(p, c));
	}
	
	queue<P> que;
	que.push(P(0, pii(0, 0)));
	
	while (!que.empty()) {
		P now = que.front(); que.pop();
		
		int cost = now.first;
		int pos = now.second.first;
		int last = now.second.second;
		
		map<int,int>::iterator it = d[pos].find(last);
		if (it != d[pos].end() && it->second <= cost) continue;
		d[pos][last] = cost;
		
		que.push(P(cost, pii(pos, 0)));
		
		vector<pii> G = g[pii(pos, last)];
		
		REP(i, G.size()) {
			int nextpos = G[i].first;
			int nextc = G[i].second;
			
			if (last == 0) que.push(P(cost + 1, pii(nextpos, nextc)));
			else que.push(P(cost, pii(nextpos, nextc)));
		}
	}
	
	int ans = d[n - 1][0];
	if (ans == 0) ans = -1;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 90084
#include<bits/stdc++.h>
#define MAX 1e9
using namespace std;

typedef long long ll;

void
chmin(int *arrdp, int cost, int index)
{
  if(cost < arrdp[index]){
    arrdp[index] = cost;
  }
  return;
}

int
main(void)
{

  int n; cin >> n;
  int arrh[100010];for(int i = 0; i < n; ++i)cin >> arrh[i];
  int arrdp[100010];
  arrdp[0] = 0;
  arrdp[1] = abs(arrh[0] - arrh[1]);


  for(int i = 2; i < n; ++i){
    arrdp[i] = arrdp[i - 1] + abs(arrh[i - 1] - arrh[i]);
    chmin(arrdp, arrdp[i - 2] + abs(arrh[i - 2] - arrh[i]), i);
  }

  cout << arrdp[n - 1] << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

#import sys
#sinput = sys.stdin.readline

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

if n%(a+b)==0:
    print(a*(n//(a+b)))
elif n%(a+b)<=a:
    print(a*(n//(a+b))+n%(a+b))
else:
    print(a*(n//(a+b))+a)


Measured memory_bytes: 3060
n=int(input())
a=[]
b=[]
for _ in range(n):
  x,y=map(int,input().split())
  a+=(x+y),
  b+=(x-y),
c=max(a)-min(a)
d=max(b)-min(b)
ans=max(c,d,-c,-d)
print(ans)

Measured memory_bytes: 97796
#include <stdio.h>

typedef struct _exam_dataset_st
{
    int midterm, final, makeup;
} exam_dataset_st;

char get_performance(exam_dataset_st *dataset)
{
    if (!dataset)
    {
        return 'G';
    }
    int total = dataset->midterm + dataset->final;
    return (dataset->midterm == -1 || dataset->final == -1) ? 'F' :
           (total >= 80) ? 'A' :
           (total >= 65) ? 'B' :
           (total >= 50) ? 'C' : (total >= 30) ? (dataset->makeup >= 50 ? 'C' : 'D') : 'F';
}

int main(int argc, char *argv[])
{
    exam_dataset_st exam_datasets[50] = {};
    int count = 0;
    for (exam_dataset_st *elm = exam_datasets, *const end = elm + 50; elm != end; ++count, ++elm)
    {
        int midterm, final, makeup;
        scanf("%d %d %d", &midterm, &final, &makeup);
        if (midterm == -1 && final == -1 && makeup == -1)
        {
            break;
        }
        *elm = (exam_dataset_st){.midterm = midterm, .final = final, .makeup = makeup};
    }
    for (exam_dataset_st *elm = exam_datasets, *const end = elm + count; elm != end; ++elm)
    {
        printf("%c\n", get_performance(elm));
    }
    return 0;
}



Measured memory_bytes: 2068
n, k, q = map(int, input().split())
A = []

for i in range(q):
		A.append(int(input()))

points = [k-q for i in range(n)]

for i in A:
		points[i-1] += 1


for i in  points:
		if i <= 0:
				print("No")
		else: 
				print("Yes")


Measured memory_bytes: 11776
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,m,ans=0;
    cin>>n>>m;
    bool b[n-1]={};
    vector<pair<int,int>>ab(m);
    for(int i=0;i<m;i++)cin>>ab[i].second>>ab[i].first;
    sort(ab.begin(),ab.end());
    for(int i=0;i<m;i++){
        bool f=false;
        for(int j=ab[i].first-2;j>=ab[i].second-1;j--)if(f|=b[j])break;
        if(!f)b[ab[i].first-2]=true;
    }
    for(int i=0;i<n-1;i++)ans+=b[i];
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;


void Main(){
    char c, d; cin >> c;
    string s = "AT";
    string t = "CG";
    
    rep(i, 2){
        if(c == s[i]) d = s[1-i];
        if(c == t[i]) d = t[1-i];
    }
    cout << d << endl;
    return;
}

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

Measured memory_bytes: 3588
/*
	最后一步一定是 (1, 0)
	从小往大搜, 多加剪枝
*/
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

const LL inf = 1e18;
const int mod = 1e9 + 7;

int res;
LL ans, x, y;
LL fib[100] = {0, 1};

LL tA, tB;
bool dfs(int dep, LL A, LL B) {
	if(A * fib[dep + 1] + B * fib[dep] > y) return false;
	if(A * fib[dep] + B * fib[dep - 1] > x) return false;
	if(dep == 1) {
		ans = (ans + (y - B) / A) % mod;
		if(A <= y && B <= x)
			ans = (ans + (x - B) / A) % mod;
		return true;
	}
	for(int i = 1 + (!B); true; ++i) {
		tB = A, tA = i * A + B;
		if(!dfs(dep - 1, tA, tB))
			return i > 1;
	}
}

int main() {
//	freopen("fibo.in", "r", stdin);
//	freopen("fibo.out", "w", stdout);
	for(int i = 1; fib[i] < inf; ++i)
		fib[i + 1] = fib[i] + fib[i - 1];
	
	int q;
	scanf("%d", &q);
	for(int tim = 1; tim <= q; ++tim) {
		scanf("%lld%lld", &x, &y);
		if(x > y) swap(x, y); // x <= y

		int o = 0;
		while(fib[o + 1] <= x) ++o;
		if(fib[o + 1] > y) --o;
		
		ans = 0;
		res = o - 1;
		if(!res) res = 1;
		
		if(res == 1) {
			printf("1 %lld\n", x == 2 ? 4 : y % mod);
			continue;
		}
		
		dfs(res, 1, 0);
		printf("%d %lld\n", res, ans);
	}
	return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define pb push_back

const int N = 1e5 + 100;

vi adj[N];
int indeg[N];
int dp[N];

int dfs(int v, int p) {
    if (dp[v]) {
        return dp[v];
    }
    int best = 0;
    for (int u:adj[v]) if (u != p) {
        best = max(best, 1 + dfs(u, v));
    }
    dp[v] = best;
    return dp[v];
}

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    while (m--) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].pb(y);
        indeg[y]++;
    }
    for (int i=0; i<n; i++) {
        if (indeg[i] == 0) {
            dfs(i, i);
        }
    }
    int ans = *max_element(dp, dp+n);
    cout << ans << '\n';
}


Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int main(void)
{
	int a,b,c,z;
	cin>>a>>b>>c;
	z=0;
	for(int i=a;i<=b;i++){
		if(c%i==0){
			z++;
		}
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
    int n;
    cin >> n;
    vector<int> nums;
    for(int i = 0; i < n; ++i){
        int x; cin >> x;
        nums.push_back(x);
    }
    bool flag = true;
    for(int i = n - 2; i >= 0; i--){
        if(nums[i] > (nums[i + 1] + 1)) {flag = false; break;}
        if(nums[i] == nums[i + 1] + 1) nums[i]--;
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        for(int j = i + 1 ; j < n ; j++){
            int k = 0;
            while(((i >> k) & 1) == ((j >> k) & 1)) k++;
            cout << k + 1 << " ";
        }
        cout << endl;
    }
}


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

int main()
{
    int n;
    cin>>n;
    int a[n];

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

    int minimum=a[0];
    int cnt=0;

    for(int i=0;i<n;i++)
    {
        if(a[i]<=minimum)
        {
            minimum=a[i];
            cnt++;
        }
    }

    cout<<cnt<<endl;
    exit(0);
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N;cin>>N;cout << (N+1)/2 << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S) - 1
ans = 0

for i in range(2 ** N):
    k = 0
    for j in range(N):
        if (i >> j) & 1:
            ans += int(S[k:j + 1])
            k = j + 1
    ans += int(S[k:])
print(ans)


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

typedef long long ll;

int main(){
    string s, T;
    cin >> s >> T;
    vector<string> S(10000);
    
    int cnt=0, fcnt=0;
    for(int i=0; i<(int)s.size()-(int)T.size()+1; i++){
        
        bool flag=true;
        for(int j=0; j<(int)T.size(); j++){
            if(s[i+j]!='?' && s[i+j]!=T[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            for(int k=0; k<s.size(); k++){
                if(k==i)
                    S[cnt] += T;
                else if(k<i || k>=i+T.size()){
                    if(s[k]!='?')
                        S[cnt].push_back(s[k]);
                    else
                        S[cnt].push_back('a');
                }
            }
            //cout << S[cnt] << endl;
            cnt++;
        }
        else fcnt++;
    }
    if(fcnt==(int)s.size()-(int)T.size()+1)
        cout << "UNRESTORABLE" << endl;
    else {
        sort(S.begin(),S.end());
        S.erase(unique(S.begin(),S.end()), S.end());
        cout << S[1] << endl;
    }
}



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

int n_dig(int a) {
    if (a == 0) return 1;
    int ret = 0;
    while (a) { a /= 10; ++ret; }
    return ret;
}

int dig(int a, int k) {
    int p = n_dig(a) - k;
    while (p) { a /= 10; --p; }
    return a % 10;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M), c(M);
    for (int i=0; i<M; ++i) cin >> s[i] >> c[i];
    
    for (int x=0; x<1000; ++x) {
        if (n_dig(x) != N) continue;
        bool flag = true;
        for (int i=0; i<M; ++i) flag &= (dig(x,s[i]) == c[i]);
        if (flag) {
            cout << x << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

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

using namespace std;

int main(){
  int N,A[110],sum;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> A[i];
  }sort(A,A+N,greater<int>());
  sum=A[0];
  sort(A,A+N);
  sum=sum-A[0];
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXM 30000
using namespace std;
int n;
int main()
{
    scanf("%d",&n);
    if(n==3)
    {
        printf("2 5 63");
        return 0;
    }
    //大于等于4是因为要给2和4留两个位置以便加得6
    for(int x=3;x+6<MAXM&&n>=4;x+=12,n-=2)
    {
        printf("%d %d ",x,x+6);
    }
    int x=2;
    for(;n>=3;x+=6,n-=3)
    {
        printf("%d %d %d ",x,x+2,x+4);
    }
    if(n==1)
    {
        printf("%d ",x+4);
    }
    else if(n==2)
    {
        printf("%d %d ",x,x+2);
    }
}


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

const int INF = 1e9;

int w[100010];

bool check( int mid, int N, int k ){
  int sum = 0;
  for( int i = 0; i < N; i++ ){
    if( sum + w[i] > mid ){
      sum = w[i];
      k--;
    }else{
      sum += w[i];
    }
    
    if( sum > mid ) return false;
    if( k <= 0 ) return false;
    
  }
  return true;
}

int main(){
  int n, k; cin >> n >> k;
  for( int i = 0; i < n; i++ ) cin >> w[i];
  
  int left = 0;
  int right = INF;
  while( right - left > 1 ){
    int mid = ( right + left ) / 2;
    if( check( mid, n, k ) ){
      right = mid;
    }else{
      left = mid;
    }
  }

  cout << right << endl;
}



Measured memory_bytes: 3484
import java.util.*;

public class Main {

	public static int half(int a[], int k) {
		int l = 0, r = a.length;
		int m = (l + r) / 2;
		while (l + 1 < r) {
			m = (l + r) / 2;
			if (a[m] > k)
				r = m;
			else
				l = m;
		}
		return r;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), a[] = new int[n];
		for (int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		sc.close();
		Arrays.sort(a);
		int ans = a[n - 1];
		int tmp = half(a, ans / 2);
		int ans2 = a[tmp];
		if (tmp != 0) {
			if (a[tmp] - ((ans / 2) + ans % 2) > Math.abs(a[tmp - 1] - (ans / 2)))
				ans2 = a[tmp - 1];
		}
		if (ans2 == ans)
			ans2 = a[tmp - 1];

		System.out.println(ans + " " + ans2);
	}

}


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

int main() {
  int n;
  cin>>n;
  vector<ll> sum_a(n+1);
  sum_a[0]=0;
  map<ll,ll> mp;
  mp[0]=1;
  rep(i,n){
    int A;
    cin>>A;
    sum_a[i+1]=sum_a[i]+A;
    mp[sum_a[i+1]]++;
  }
  ll ans=0;
  for(auto x : mp){
    ans+=x.second*(x.second-1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int n;
  cin >> n;
  cout << 48 - n;
    return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll ans=n*(n-1);
	ans/=2;
	cout<<ans<<"\n";
return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  OK((abs(a-b) <= d && abs(c-b) <= d) or (abs(a-c) <= d))

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string str;
  cin>>str;
  for(int i=0;i<str.size();i+=2)
  {
   if(str[i]=='h'&&str[i+1]=='i')
   {
     continue;
   }
   else
   {

        cout<<"No\n";
      return 0;
   }

  }

 cout<<"Yes\n";

 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    unordered_map<string, int> um;
    rep(i,n){
        string s; cin >> s;
        sort(s.begin(), s.end());
        um[s]++;
    }
    ll ans = 0;
    for(pair<string, int> p: um){
        int cnt = p.second;
        if(cnt >= 2){
            ans += ((ll)cnt * (cnt - 1)) / 2;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 10384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>

using namespace std;
typedef long long ll;

ll lcm(ll a,ll b){
  while(b!=0){
    ll c=a%b;
    a=b;
    b=c;
  }
  return a;
}

int main(){
  ll n,t[101];
  scanf("%lld",&n);
  for(ll i=0;i<n;i++){
    scanf("%lld",&t[i]);
  }

  ll ans=t[0];
  for(ll i=1;i<n;i++){
    ans=(ans/lcm(ans,t[i]))*t[i];
  }

  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 505;
int a[maxn][maxn]={0};
int dis[maxn][maxn]={0};
int num[maxn*maxn]={0};
int main()
{
    int n;
    cin >> n;
    int ans  =0 ;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            dis[i][j]=min({i-1,j-1,n-i,n-j});
            a[i][j]=1;
        }
    }
    for(int i=0;i<n*n;i++){
        cin >> num[i];
        int row = num[i]%n;
        if(row==0)
            row=n;
        int col = (num[i]-1)/n+1;
        queue<pair<int,int>>q;
        q.push({row,col});
        ans+=dis[row][col];
        a[row][col]=0;
        while(!q.empty()){
            if(row==0||col==0){
                q.pop();
                continue;
            }
            row = q.front().first;
            col = q.front().second;
            q.pop();
            if(dis[row][col]+a[row][col]<dis[row+1][col]){
                dis[row+1][col]=dis[row][col]+a[row][col];
                q.push({row+1,col});
            }
            if(dis[row][col]+a[row][col]<dis[row][col+1]){
                dis[row][col+1]=dis[row][col]+a[row][col];
                q.push({row,col+1});
            }
            if(dis[row][col]+a[row][col]<dis[row-1][col]){
                dis[row-1][col]=dis[row][col]+a[row][col];
                q.push({row-1,col});
            }
            if(dis[row][col]+a[row][col]<dis[row][col-1]){
                dis[row][col-1]=dis[row][col]+a[row][col];
                q.push({row,col-1});
            }
        }
    }
    cout << ans <<endl;
    return 0;
}


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

using namespace std;

const int MAXN = 1e5 + 10;

int n, m, x[MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	while (m--){
		int a, b; cin >> a >> b, a--, b--;
		x[a] ^= 1;
		x[b] ^= 1;
	}
	for (int i = 0; i < n; i++)
		if (x[i]){
			cout << "NO\n";
			return 0;
		}
	cout << "YES\n";
	return 0;
}


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

using namespace std;

int n;
int arr[100100];

int main() {
    int i;
    
    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%d",&arr[i]);
    sort(arr,arr+n);
    int mini = 2e9, t = 0;
    for (i=0;i<n-1;i++) {
        if (mini>abs(arr[n-1]-2*arr[i])) {
            mini=abs(arr[n-1]-2*arr[i]);
            t=arr[i];
        }
    }
    printf("%d %d\n",arr[n-1],t);
    
    return 0;
}


Measured memory_bytes: 640
N = int(input())
H = list(map(int,input().split()))

def main():
    if N==2:
        print(abs(H[1] - H[0]))
        return

    costs = [0 for _ in range(N)]
    costs[1] = abs(H[1]-H[0])
    costs[2] = min(costs[0] + abs(H[1]-H[0]), abs(H[2]-H[0])) # 0>1>2と0>2のmin

    for i in range(2,N):
        step_1 = abs(H[i] - H[i-1]) # 1段上る
        step_2 = abs(H[i] - H[i-2]) # 2段上る
        # 漸化式 fn = min(fn-1, fn-2)
        costs[i] = min(costs[i-1] + step_1, costs[i-2] + step_2) 
    print(costs[-1])
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 54588
#include<stdio.h>
char mark(int num);
int main(){
	int h, w;
	int i, j;
	while(1){
		scanf("%d %d", &h, &w);
		if(h == 0 && w == 0)break;
		for(i = 0;i < h;i++){
			for(j = 0;j < w;j++){
				printf("%c", mark(i + j));
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

char mark(int num){
	if(num%2==0){
		return '#';
	}
	else{
		return '.';
	}
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int mod = 1000000007;
const int max_n = 200005;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    ll n;cin >> n;
    mint ans=0;
    vl v(n);rep(i,n)cin >> v[i];
    rep(i,n)ans+=v[i];
    ans*=ans;
    rep(i,n){
        ans-=v[i]*v[i];
    }
    cout << ans/2 <<endl;
}

Measured memory_bytes: 4772
#include <iostream>

using namespace std;

int main()
{
    int c=3;
    int v[c-1];
    for (int i=0; i<c; i++)
    {
        cin>>v[i];
    }
    int aux = v[0];
    v[0] = v[2];
    v[2] = v[1];
    v[1] = aux;

    for(int j=0; j<c; j++)
    {
        cout<<v[j]<<" ";
    }

    return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int x;
    int x1 = 0;
    int x2 = 0;
    int x3 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        if (x <= a) {
            x1++;
        } else if (x <= b) {
            x2++;
        } else {
            x3++;
        }
    }
    cout << min(min(x1, x2), x3) << endl;
    return 0;
}


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

ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

int main(){
    int X, Y;
    cin >> X >> Y;
    if ((X+Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int s, t;
    s = (2*X-Y)/3;
    t = (2*Y-X)/3;
    
    if (s < 0 || t < 0) {
        cout << 0 << endl;
        return 0;
    }
    
    ll ans = 1;
    for (ll i = t+1; i <= s+t; i++) {
        ans *= i;
        ans %= mod;
    }
    for (ll i = 1; i <= s; i++) {
        ans *= modinv(i);
        ans %= mod;
    }
    cout << ans << endl;
    
    return 0;
}

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

typedef long long ll;

int main(){
	string ans;
	ll N, cnt=0, s=2;
	cin >> N;
	
	if(N == 0){
		cout << 0 << endl;
		return 0;
	}
	
	for(int i=0; N != 0; i++){
		if(N%s != 0){
			ans[i] = '1';
			N -= s/2*((int)pow(-1, i));
		} else {
			ans[i] = '0';
		}
		s *= 2;
		cnt++;
	}
	
	for(int i=cnt-1; i >= 0; i--){
		cout << ans[i] - '0';
	}
	 cout << endl;
	 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  ll N; cin >>N;
  /*
  4/N = 1/h + 1/n + 1/w
  4*h*n*w = N*n*w + N*h*w + N*h*n
  n*(4*h*w - N*w - N*h) = N*h*w
  n = N*h*w / (4*h*w - N*w - N*h)
   */
  for (ll h=1; h<=3500; h++){
    for (ll w=1; w<=3500; w++){
      ll tmp = 4*h*w - N*w - N*h;
      if (tmp <= 0) continue;
      if (N*h*w % tmp > 0) continue;
      ll n = N*h*w / tmp;
      cout <<h <<" " <<n <<" " <<w <<endl;
      return 0;
    }
  }
}


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

int main(){
  int N;
  cin >> N;
  priority_queue<P> Q;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    Q.push(make_pair(x, i));
  }
  for(int i = 0; i < N; i++){
    P p;
    p = Q.top();
    if(p.second == i){
      Q.pop();
      cout << Q.top().first << endl;
      Q.push(p);
    } 
    else cout << Q.top().first << endl;
  }
}

Measured memory_bytes: 3312
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
	Node *cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;

	while (1) {
		if (cur == nil) break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;

	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main() {
	int key, n;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; ++i) {
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6) {
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}

	printList();
}


Measured memory_bytes: 33932
import java.util.Arrays;
import java.util.Scanner;

class Main {
    
    private static final int N = 50000;
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        Arrays.sort(arr);
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum += arr[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 30048
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>

using namespace std;

int main() {
  while (true) {
    string d;
    cin >> d;
    if (d == "-") break;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      int h;
      cin >> h;
      string bottom = d.substr(0, h);
      string top = d.substr(h, string::npos);
      d = top + bottom;
    }
    cout << d << endl;
  }
}

Measured memory_bytes: 3140
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
const int MaxN = 1e5;
int a[MaxN + 5];
int b[MaxN + 5];
int main()
{
	int n, i,c = 0;
	scanf("%d", &n);
	for(i = 1 ; i <= n ; i++)
	{
		scanf("%d", &a[i]);
		if(a[i] <= 1e5)
		{
			b[a[i]]++;
		}
		else
		{
			c++;
		}
	}
	if(n == 1)
	{
		if(a[1] == 1)
		{
			printf("0\n");
		}
		else
		{
			printf("1\n");
		}
	}
	else
	{
		int sum = 0;
		for(i = 1 ; i <= 100004 ; i++)
		{
			if(b[i] != 0)
			{
				if(b[i] > i )
				{
					sum = sum + b[i] - i;
				}
				if(b[i] < i)
				{
					sum = sum +b[i];
				}
			}
		}
		printf("%d\n",sum + c);
	}
	return 0;
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int h,w;
    cin >> h >> w;

    vector<string> s(h);

    rep(i, h){
        cin >> s[i];
    }

    rep(i, h + h){
        rep(j, w){
            cout << s[i / 2][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int a, b, c, x, y;
  std::cin >> a >> b >> c >> x >> y;
  int cost = 0;

  int greater_xy = std::max(x, y);
  int smaller_xy = std::min(x, y);

  // 小さい方に合わせるケース
  int smallercost = 0;
  if(x > y) {
    // yができる分購入する
    smallercost += 2*y*c;
    int sub = x - y;
    smallercost += a*sub;
  } else {
    smallercost += 2*x*c;
    int sub = y - x;
    smallercost += b*sub;
  }

  // 大きい方に合わせるケース
  int biggercost = 0;
  if(x > y) {
    biggercost += 2*x*c;
  } else {
    biggercost += 2*y*c;
  }


  int simplecost = a*x+b*y;
  cost = std::min(smallercost, biggercost);
  cost = std::min(cost, simplecost);

  std::cout << cost << std::endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N,X;
    int res=1;
    cin>>N>>X;
    int L[100];
    int D[100]={0};
    for(int i=0;i<N;i++){
        cin>>L[i];
        D[i+1]=D[i]+L[i];
        if(D[i+1]<=X){
            ++res;
        }
        
    }
    cout<<res<<endl;
}


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

int main()
{
int n;
cin >> n;
vector<int> v(n);
for(int i = 0; i < n; i++)
{
	cin >> v[i];
}
sort(v.begin(), v.end());

int ans = v[v.size()/2] - v[v.size()/2 - 1];
cout << ans << endl;
return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	string a,b,c;
	cin >> a>>b>>c; 
	cout << a[0]<<b[1]<<c[2]<< '\n';//endlは遅いのでこちらを使う習慣をつける
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,d,g,nzd;
    cin >> n >> d;
    cin >> g;
    nzd=abs(g-d);
    for (int i=1;i<n;i++)
    {
        cin >> g;
        nzd=__gcd(nzd,abs(g-d));
    }
    cout << nzd;
}


Measured memory_bytes: 3616
H, W, K = map(int, input().split())
mod = 10 ** 9 + 7
dp_H1 = [[0] * 2 for _ in range(W + 1)]
#dp_H1: H=1の縦棒をi本用意した時、できるあみだの組み合わせはdp_H1[i][0]+dp_H1[i][1]

dp_row_where = [[0] * (W + 2) for _ in range(H + 1)]
#dp_row_where[i][j]: i行目の時点で、j本目の縦棒に到達できる組み合わせ

dp_H1[0][0] = 1
dp_H1[1][0] = 1

for i in range(2, W + 1):
	dp_H1[i][0] = dp_H1[i - 1][0] + dp_H1[i - 1][1]
	dp_H1[i][0] %= mod
	dp_H1[i][1] = dp_H1[i - 1][0]
	dp_H1[i][1] %= mod

dp_row_where[0][1] = 1

for i in range(1, H + 1):
	for j in range(1, W + 1):
		#j番目の縦棒から真下に降りる場合
		dp_row_where[i][j] += dp_row_where[i - 1][j] * sum(dp_H1[j - 1]) * sum(dp_H1[W - j])
		#print(sum(dp_H1[j - 1]), sum(dp_H1[W - j]))
		#j-1番目の縦棒から到達する場合
		dp_row_where[i][j] += dp_row_where[i - 1][j - 1] * sum(dp_H1[j - 2]) * sum(dp_H1[W - j])
		
		#j+1番目の縦棒から到達する場合
		dp_row_where[i][j] += dp_row_where[i - 1][j + 1] * sum(dp_H1[j - 1]) * sum(dp_H1[W - j - 1])
		
		dp_row_where[i][j] %= mod
		
print(dp_row_where[H][K])
#print(dp_H1)
#print(dp_row_where)


Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
bool f[1005];
int main(void){
	int N;cin >> N;
	int A[N+1][N+1];
	vector<int> v(1005,1);
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N-1;j++){
			cin >> A[i][j];
		}
	}
	int ans = 0;
	bool ok = 1;
	while(ok){
		ok = 0;
		ans ++;
		//cout << ans <<"日目" << endl;
		for(int i=1;i<1005;i++)f[i] = 1;
		for(int i=1;i<=N;i++){
			if(v[i]==N)continue;
			int op = A[i][v[i]];//opは対戦相手の番号
			if(A[op][v[op]] == i && f[op]*f[i] == 1){
				//cout << i << "vs" << op << endl;
				v[op]++;
				v[i] ++;
				f[op] = 0;
				f[i]  = 0;
				ok = 1;
			}
		}
		if(!ok)ans--;
	}
	ok = 1;
	for(int i=1;i<=N;i++){
		if(v[i]!=N)ok = 0;
		
	}
	if(ok){
		cout << ans << endl;
	}else{
		cout << -1 << endl;
	}
}

Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
int DP[101][101][1000];

signed main() {
	int N, W; cin >> N >> W;
	vector<int>w(N), v(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	int w0 = w[0];
	for (int i = 0; i < N; i++) w[i] -= w0;

	for (int i = 0; i <= N; i++)for (int j = 0; j <= N; j++)for (int k = 0; k < 1000; k++)DP[i][j][k] = -1;

	DP[0][0][0] = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k < 500; k++) {
				if (DP[i][j][k] == -1)continue;

				DP[i + 1][j + 1][k + w[i]] = max(DP[i + 1][j + 1][k + w[i]], DP[i][j][k] + v[i]);
				DP[i + 1][j][k] = max(DP[i + 1][j][k], DP[i][j][k]);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= min((int)500,W - w0*i); j++) {
			ans = max(ans, DP[N][i][j]);
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 80000
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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


	int a;cin>>a;
  cout<<a*a*a<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    sort(a.rbegin(),a.rend());
    //rep(i,n)cout << a[i] << endl;
    priority_queue<int> pq;
    ll ans =0;
    rep(i,n){
        if(pq.size()==0)pq.push(a[i]);
        else{
            ans+=pq.top();pq.pop();
            pq.push(a[i]);
            pq.push(a[i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4600
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int x =0;
    int max =0;
    for (int i=0; i<N; i++) {
      if (S.charAt(i) == 'D') {
        x--;
      }
      if (S.charAt(i) == 'I') {
        x++;
        if (x > max) max = x;
      }
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 22868