akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct edge
{
	int s, t, c, d,rev;
	edge(int s, int t, int c, int d,int rev) :s(s), t(t), c(c),d(d), rev(rev) {}
	edge() { s = -1, t = -1, c = -1, rev = -1; d = -1; }
};

vector<vector<edge>> G;
int dist[101];
int prevv[101], preve[101];

int min_cost_flow(int s, int t, int f)
{
	int res = 0;

	while (f > 0)
	{
		rep(i, 0, 101)dist[i] = INF;
		dist[s] = 0;
		while (true)
		{
			bool update = false;

			rep(i, 0, SZ(G))
			{
				if (dist[i] == INF)
				{
					continue;
				}
				rep(j, 0, SZ(G[i]))
				{
					edge e = G[i][j];
					if (e.c > 0 && dist[e.t] > dist[i] + e.d)
					{
						dist[e.t] = dist[i] + e.d;
						prevv[e.t] = i;
						preve[e.t] = j;
						update = true;
					}
				}
			}

			if (!update)
			{
				break;
			}
		}

		if (dist[t] == INF)
		{
			return -1;
		}

		int tf = f;
		for (int i = t; i != s; i = prevv[i])
		{
			chmin(tf, G[prevv[i]][preve[i]].c);
		}
		f -= tf;
		res += tf*dist[t];
		for (int i = t; i != s; i = prevv[i])
		{
			G[prevv[i]][preve[i]].c -= tf;
			G[i][G[prevv[i]][preve[i]].rev].c += tf;
		}
	}

	return res;
}

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

	int V, E, F,s, t, c, d;
	cin >> V >> E >> F;
	G.resize(V);
	rep(i, 0, E)
	{
		cin >> s >> t >> c >> d;
		G[s].push_back(edge(s, t, c, d,SZ(G[t])));
		G[t].push_back(edge(t, s, 0, -d,SZ(G[s]) - 1));
	}

	cout << min_cost_flow(0,V-1,F) << endl;

	return 0;
}


Measured memory_bytes: 3304
void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const M = scan!int;
  const Heights = scan!long(N);
  const Pathes = M.iota.map!(x => scan!int(2)).map!(x => [x[0] - 1, x[1] - 1]).array;

  void solve() {
    int[][] allPathes;
    allPathes.length = N;
    allPathes[] = [];

    foreach(p; Pathes) {
      allPathes[p[0]] ~= p[1];
      allPathes[p[1]] ~= p[0];
    }

    int answer;
    foreach(i; 0..N) {
      if (allPathes[i].any!(x => Heights[x] >= Heights[i])) continue;

      answer++;
    }

    writeln(answer);
  }

  solve();
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


Measured memory_bytes: 21168
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ll n,w;
	cin>>n>>w;
	ll a[n][2];
	ll sum=0,wei=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1];
		sum+=a[i][1];
		wei+=a[i][0];
	}
	ll dp[sum+1];
	for(ll i=0;i<=sum;i++)
	{
		dp[i]=1000000000;
	}
	dp[0]=0;
	dp[sum]=wei;
	for(ll i=0;i<n;i++)
	{
		for(ll j=sum;j>=a[i][1];j--)
		{
			if(min(dp[j],dp[j-a[i][1]]+a[i][0])<=w)
			dp[j]=min(dp[j],dp[j-a[i][1]]+a[i][0]);
		}
	}
	for(ll i=sum;i>0;i--){
		if(dp[i]<=w)
		{
			cout<<i;
			break;
		}
	}
}

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


int main(){

    ll A,B,C,D;

    cin >> A >> B >> C >> D;

    while (true)
    {
        C -= B;
        if(C <= 0)
        {
            cout << "Yes";
            break;
        }

        A -= D;
        if(A <= 0)
        {
            cout << "No";
            break;
        }
    }
    

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <tuple>
#include <numeric>
#include <utility>
#include <climits>
#include <float.h>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#pragma GCC target ("avx2")

using namespace std;

typedef long long ll;
typedef long double ld;
constexpr ll INF = LLONG_MAX;
constexpr double DINF = DBL_MAX;
constexpr ll mod = 1e9+7;
constexpr double PI = M_PI;

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...));
}

int main(){
  	cin.tie(0);
  	cout.tie(0);
  	ios::sync_with_stdio(false);
	
	int n;
	string s, t;
	cin >> n >> s >> t;
	for(int i = 0; i < n; i++){
		cout << s[i] << t[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

LeftBlack  = [0]*N
RightWhite = [0]*N

LeftBlack[0]=0
for i in range(1,N):
    if S[i-1] == '#':
        LeftBlack[i]=LeftBlack[i-1]+1
    else:
        LeftBlack[i]=LeftBlack[i-1]

RightWhite[N-1]=0
for i in range(N-2,-1,-1):
    if S[i+1] == '.':
        RightWhite[i] = RightWhite[i+1]+1
    else:
        RightWhite[i] = RightWhite[i+1]

ans = N
for i in range(N):
    if S[i] == '.':
        n = LeftBlack[i]+RightWhite[i]
    else:
        n = LeftBlack[i]+RightWhite[i]+1
    ans = min(ans,n)

b = 0
w = 0
for i in range(N):
    if S[i]=='.':
        b +=1
    else:
        w +=1
ans = min(ans,b)
ans = min(ans,w)

print(ans)

Measured memory_bytes: 12816
#include"stdio.h"

int main()
{
	int n,a[10];
	int t,p=0,i;
	scanf("%d",&n);
	while(1)
	{
		a[p]=n%10;
		p++;
		n/=10;
		if(n==0)
		break;
	}
    int f=0;
	if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]||a[0]==a[1]&&a[1]==a[2]&&a[2]==a[3]&&a[3]==a[0])
    f=1;
    
    if(f==1)
    printf("Yes\n");
    else
    printf("No\n");
   
    
}

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

int main(){
  int64_t A,B,d,mgd;
  cin >> A >> B;
  d=1;
  mgd=1;
  if(A>B){
    for(int d=1;d<=B;d++){
      if(A%d==0 && B%d==0){
        mgd=d; //最大公約数
      }
    }
  }
  if(A<B){
    for(int d=1;d<=A;d++){
      if(A%d==0 && B%d==0){
        mgd=d; //最大公約数
      }
    }
  }
    cout << (A*B)/mgd << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k<=a) cout << k << endl;
  else if(a < k and k <=a+b) cout << a << endl;
  else if(a+b<k and k <=a+b+c) cout << a - (k-a-b) << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string.h>
#include<cstdlib>


using namespace std;
struct Node
{
	int key;//??°?????¬????????´??°key
	Node *next, *prev;//???????????????????´??????????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()
{
	//malloc???C????¨?????????????????????°?????¨?????¨?????????????????§?°???????????????´???sizeof???Node????????????Node?±???????????????´?????§?°?
	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)
			cout << " ";
		cout << cur->key;//?????°????????????
		cur = cur->next;//?????????????????????
	}
	cout << endl;
}
void deleteNode(Node *t)
{
	if (t == nil) return;//???t?????´????????¶????????????
	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;//n???????????°
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	cin >> n;
	init();
	for (int i = 0; i < n; i++)//????????????????°±???????¬???????
	{
	        //scanf("%s%d",com,&key);
		cin >> com ;
		if (com[0] == 'i')
		{
		        cin>> key;
			insert(key);
			np++;
			size++;
			//cout<<"finish"<<endl;
		}
		else if (com[0] == 'd')
		{
		       // cout<<"right";
			if (strlen(com) > 6)
			{
			        //cout<<"finish"<<endl;
				if (com[6] == 'F')
					deleteFirst();
				else if (com[6] == 'L')
					deleteLast();

			}
			else
			{
			        cin>> key;
				deleteKey(key);
				nd++;
			}
			size--;
		}
	}
	printList();
	return 0;
}

Measured memory_bytes: 34248
#include<stdio.h>

int main(){
	int S;
	int h;
	int m;
	int s;
	
	scanf("%d",&S);
	
	h = S /3600;
	m = S %3600 /60;
	s = S %3600 %60;
	
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}
	

Measured memory_bytes: 592
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N 10000

int main(){
  int a[N], f = 0, g, i, n, x = 3;
  
  
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    if((scanf("%d", &a[i])) == EOF)
      break;
    
    if(a[i] == 2 || a[i] == 3 || a[i] == 5 || a[i] == 7)
      f++;
    
    else if(a[i] % 2 != 0){
      g = 1;
      while(sqrt(a[i]) >= x){
		
	if(a[i] % x == 0){
	  g++;
	  break;
	}
	
	x += 2;
	g = 0;
      }
      
      if(g == 0){
	f++;
	}
      
      x = 3;
    }
  }
  
  printf("%d\n", f);
  
  
  return 0;
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n, m;
    string ans;
    cin >> n >> m;
    vector<pair<int, int>> condision(m);
    rep(i, m) {
        cin >> condision[i].first >> condision[i].second;
        condision[i].first--;
    }

    bool ok;
    rep(i, 1000) {
        ok = true;
        ans = to_string(i);
        if (ans.length() != n) continue;
        rep(j, m) if (ans[condision[j].first] != (char) (condision[j].second + '0')) ok = false;
        if (ok) {
            cout << i << endl;
            return 0;
        }

    }

    cout << "-1" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n;
  cin>>n;
  int ans=10;
  for(long long int i=1;i<=sqrt(n);i++){
    if(n%i!=0) continue;
    long long int a=i;
    long long int b=n/i;
    string s=to_string(a);
    string m=to_string(b);
    int f=max(s.size(),m.size());
    ans=min(ans,f);
  }
  cout<<ans;


}


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

int main() {
    string s;
    cin >> s;
    bool flag = true;
    rep(i, s.size()) {
        if(i % 2 == 0 && s[i] == 'L') flag = false;
        if(i % 2 > 0 && s[i] == 'R') flag = false;
    }
    cout << (flag ? "Yes" : "No") << endl;
}


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

int main() {
  string word;
  stack<int> S;
  int i;
  while (cin >> word) {
    if (word == "+") {
      i = S.top();
      S.pop();
      i += S.top();
      S.pop();
      S.push(i);
    }
    else if (word == "-") {
      i = S.top();
      S.pop();
      i = S.top() - i;
      S.pop();
      S.push(i);
    }
    else if (word == "*") {
      i = S.top();
      S.pop();
      i *= S.top();
      S.pop();
      S.push(i);
    }
    else {
      S.push(stoi(word));
    }
  }
  cout << S.top() << endl;
  return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#include<string>
using namespace std;
string a,b,c,ans;
bool ok(int s)
{
	for(int i=s;i<s+b.length();i++)
	{
		if(a[i]!='?'&&a[i]!=b[i-s])
			return false;
	}
	return true;
}
string replace(int s,int e)
{
	string temp;
	temp=a;
	for(int i=s;i<=e;i++)
	{
		temp[i]=b[i-s];
	}
	return temp;
}
int main()
{
	int t=0;
	cin>>a>>b;
	int la=a.length(),lb=b.length();
	for(int i=0;i<=la-lb;i++)
	{
		string c=a;
		if(ok(i))
		{
			c.replace(i,lb,b);
//			cout<<c<<endl;
			if(t==0)
			{
				ans=c;t++;
			}
			else
			{
				if(ans>c) ans=c; 
			}
		}
	}
	if(ans=="")
	{
		cout<<"UNRESTORABLE";return 0;
	}
	for(int i=0;i<=ans[i]!='\0';i++)
	{
		if(ans[i]=='?')
			cout<<'a';
		else
			cout<<ans[i];
	}	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100


void bubbleSort(int *A , int N){
  int i,j;
  int temp;
  int minj;
  int num = 0;

  for(i = 0 ; i < N ; i++){
    minj = i;
    for( j = i ; j < N ; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    if(i != minj) num++;
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
  }
  for(i = 0 ; i < N ; i++){
    printf("%d", A[i]);
    if(i != N-1) printf(" ");
  }
  printf("\n");
  printf("%d\n", num);

  return;
}

int main(void){

  int N;
  int A[MAX];
  int i;

  scanf("%d",&N);

  for(i = 0 ; i < N ; i++){
    scanf("%d",&A[i]);
  }

  bubbleSort(A, N);


  return 0;
}

Measured memory_bytes: 604
import java.util.*;

public class Main {

	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		long n = Long.parseLong(sc.next());
		long k = Long.parseLong(sc.next());

		System.out.println(Math.min(n % k, k - (n % k)));
	}
}


Measured memory_bytes: 35396
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long long>A(N+1);
  vector<long long>B(N);
  for(int X=0;X<N+1;X++){
    cin>>A[X];
  }
  for(int X=0;X<N;X++){
    cin>>B[X];
  }
  long long K=0;
  for(int X=0;X<N;X++){
    if(B[X]<=A[X]){
      K+=B[X];
      A[X]-=B[X];
    }
    else if(B[X]>=A[X]+A[X+1]){
      K+=A[X]+A[X+1];
      A[X]=0;
      A[X+1]=0;
    }
    else{
      K+=B[X];
      A[X+1]+=A[X]-B[X];
      A[X]=0;
    }
  }
  cout<<K<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    if(n == 3){
        cout << "2 5 63" << endl;
        return 0;
    }
    int two[10002], three[5002], six[5002];
    int d;
    d = 2;
    for(int i = 0; i < 5000; i++){
        two[i * 2] = d;
        two[i * 2 + 1] = d + 2;
        d += 6;
    }
    d = 3;
    for(int i = 0; i < 5000; i++){
        three[i] = d;
        d += 6;
    }
    d = 6;
    for(int i = 0; i < 5000; i++){
        six[i] = d;
        d += 6;
    }
    int a = 2, b = 2, c = 0;
    while(a + b + c < n){
        if(a + b + c + 1 == n) c++;
        else if(a < 10000) a += 2;
        else if(b < 5000) b += 2;
        else c++;
    }
    for(int i = 0; i < a; i++) cout << two[i] << " ";
    for(int i = 0; i < b; i++) cout << three[i] << " ";
    for(int i = 0; i < c; i++) cout << six[i] << " ";
    cout << endl;
}


Measured memory_bytes: 3684
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	int n;
	ll k;
	cin >> n >> k;
	vector<int> a(n);

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

	vector<ll> t(n, -1);
	t[0] = 0;
	int now = 0;
	bool end = true;
	for (ll i = 1; true; i++)
	{
		int next = a[now];
		
		if (i == k)
		{
			now = next;
			break;
		}

		if (t[next] < 0)
		{
			t[next] = i;
			now = next;
			continue;
		}

		k -= t[next];
		k %= i - t[next];
		end = false;
		now = next;
		break;
	}

	if (end)
	{
		printf("%d", now + 1);
		return 0;
	}

	for (int i = 0; i < k; i++)
		now = a[now];

	printf("%d", now + 1);
	return 0;
}

Measured memory_bytes: 5288
#include<bits/stdc++.h>
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    fast;
    int k;
    cin>>k;
    string s;
    cin>>s;
    int m=s.length();
    if(k==m||k>m)
        {
            cout<<s<<endl;
            return 0;
        }
        else{
    for(int i=0;i<k;i++)
    {
      cout<<s[i];
    }
    cout<<"..."<<endl;
}
}


Measured memory_bytes: 3592
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iostream>
#include <numeric>
#include <random>
#include <set>
#include <unordered_set>
#include <vector>
#include <list>
#include <functional>

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

using namespace std;

#define LOCAL 1

#if LOCAL
#define pv(val) cerr << #val << " = " << (val) << endl
#define pvn(name, val) cerr << name << " = " << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#else
#define pv(val)
#define pvn(name, val)
#define pl
#endif

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
  if (vec.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
    os << vec.back() << '}';
  }
  return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
  if (arr.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
    os << arr.back() << '}';
  }
  return os;
}

template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U> const& p){
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}

template<class T, class U>
pair<T, U> operator+(pair<T, U> const& lhs, pair<T, U> const& rhs){
  return {lhs.first + rhs.first, lhs.second + rhs.second};
}

template<class T, class U>
pair<T, U> operator-(pair<T, U> const& lhs, pair<T, U> const& rhs){
  return {lhs.first - rhs.first, lhs.second - rhs.second};
}

template<class T, class U>
U lowerBound(function<T(U)> f, T const& val, U l, U r){
  while(l < r){
    auto m = l + (r - l) / 2;
    auto fm = f(m);
    if(fm < val){
      l = m;
    }else{
      r = m;
    }

  }
}


int main(void) {
  string s;
  int K;
  cin >> s;
  cin >> K;

  set<string> ss;
  for(int i = 0; i < s.size(); i++){
    for(int j = 1; j <= 5; j++) {
      if(i + j > s.size()) break;
      ss.insert(s.substr(i, j));
    }
  }
  //for(auto s : ss) pv(s);
  auto ite = ss.begin();
  --K;
  while(K > 0){
    ite++;
    --K;
  }
  cout << *ite << endl;


  return 0;
}


Measured memory_bytes: 1152
public class
Main
{
  private int swc;

  private void
  sort (
    int[ ] a
    )
  {
    int i, j;

    for ( i = 0; i < a.length; ++i )
    {
      for ( j = 1; j < a.length - i; ++j )
      {
        if ( a[ j ] < a[ j - 1 ] )
          swap ( a, j - 1, j );
      }
    }
  }
  
  private void
  swap (
    int[ ] a,
    int    i,
    int    j
    )
  {
    final int t = a[ i ];
    a[ i ] = a[ j ];
    a[ j ] = t;
    ++swc;
  }

  private void
  printArray (
    int[ ] a
    )
  {
    int i;

    for ( i = 0; i < a.length; ++i )
    {
      System.out.print ( a[ i ] );
      if ( i + 1 < a.length )
        System.out.print ( " " );
      else
        System.out.println ( );
    }
  }

  public void
  run (
    java.util.Scanner sc
    )
  {
    int[ ] a;
    int i, j;

    a = new int[ sc.nextInt ( ) ];
    for ( i = 0; i < a.length; ++i )
      a[ i ] = sc.nextInt ( );

    swc = 0;
    sort ( a );
    printArray ( a );
    System.out.println ( swc );
  }

  public static void
  main (
    String[ ] args
    )
  {
    ( new Main ( ) ).run ( new java.util.Scanner ( System.in ) );
  }
}

Measured memory_bytes: 19756
n, k = map(int, input().split())

a = 0
b = 0

l = list(map(int, input().split()))

for i in range(n):
  for j in range(i+1, n):
    if l[i] > l[j]:
      a += 1
      b += 1
    elif l[i] < l[j]:
      b += 1

aa = (k + 1) * k//2 - k

m = 10 ** 9 + 7
print((a * k + b * aa) % m)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long 
#define pb push_back
#define fr first
#define sc second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 7200001
#define M 1000000007
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin>>s;
if(count(all(s),'A')==0 || count(all(s),'B')==0)
cout<<"No"<<endl;
else cout<<"Yes"<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int n;
	int a,b;
	cin >> n ;
	if (n ==1) {
	cout << "Hello World" << endl;
	} else {
		cin >> a >>b;
	cout << a+b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
/*
AizuOnline A0528
Title Common Sub-String
8/18TLE
*/
#include <stdio.h>
#include <string.h>
int l1,l2;
char s1[4001];
char s2[4001];
int buf[2][4001];
//
dump(int * b)
{
        int i;
        for(i=0;i<l1;i++)
                printf("%d:",b[i]);
        printf("\n");
}
int solve(char * s1,char * s2)
{
        int i,j,maxlen,tmp;

        maxlen=0;
        memset(&buf[0][0],0,sizeof(int)*4001);
        for(i=0;i<l2;i++)
        {
                for(j=0;j<l1;j++)
                {
                        if(s1[j]==s2[i])
                                tmp= ((j==0)?0:buf[1&i][j-1]) + 1;
                        else
                                tmp=0;
                        buf[1-(i&1)][j] =tmp;        
                        if(tmp>maxlen)
                                maxlen=tmp;
                }
#ifdef DEBUG
                dump(&buf[1-(i&1)][0]);
#endif
                
        }
        return(maxlen);
}
main()
{
        int ret;


        while(EOF!=scanf("%s",s1))
        {
                scanf("%s",s2);
                l1=strlen(s1);
                l2=strlen(s2);
                ret=solve(s1,s2);
                printf("%d\n",ret);
        }
        return(0);
}

Measured memory_bytes: 588
#include<stdio.h>

int main (void){
	int a[10];
	int b, c, d;
	
	for(b = 0; b < 10; ++b){
		scanf("%d" ,&a[b]);
	}
	
	for(b = 0; b < 10; ++b){
		for(c = b + 1; c < 10; ++c){
			if(a[b] < a[c]){
				d = a[b];
				a[b] = a[c];
				a[c] = d;
			}
		}
	}
		for(b = 0; b < 3; ++b){
			printf("%d\n" ,a[b]);
		}
	


	return 0;
}

Measured memory_bytes: 600
# 2019/07/30
# AtCoder Beginner Contest 135 - B

# Input
n = int(input())
p = list(map(int, input().split()))

# Sort
wp = sorted(p)

cnt = 0
for i in range(n):
    if p[i] != wp[i]:
        cnt = cnt + 1

if cnt <= 2:
    ans = "YES"
else:
    ans = "NO"

# Output
print(ans)

Measured memory_bytes: 3060
N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了

PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M

for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for i in range(M):
  	print(w[i])


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N), ans(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    for (int i = 0; i < N; i++)
    {
        ans.at(A.at(i) - 1) = i + 1;
    }

    for (int i = 0; i < N; i++)
    {
        cout << ans.at(i) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  while(1){
    long long x,y,cnt=0;
    cin>>x>>y;
    if(x+y==0)break;
    if(x<y)swap(x,y);
    while(1){
      cnt++;
      x%=y;
      swap(x,y);
      if(y==0)break;
    }
    printf("%lld %lld\n",x,cnt);
  }
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define INF 200005
#define MOD 1000000007

int main()
{
    //freopen("output.txt","r",stdin);
    //freopen("input.txt","r",stdin);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n;
    cin >> n;
    vector<int>a;
    for(int i=0;i<n;i++)
    {
        int num;
        cin >> num;
        a.push_back(num);
    }
    sort(a.begin(),a.end());
    int counter=0;
    vector<pair<int,int>>all;
    for(int i=0;i<n;i++)
    {
        for(int k=i+1;k<n;k++)
        {
            int now=a[i]+a[k];
            all.push_back(make_pair(k+1,now));
        }
    }
    for(int i=0;i<all.size();i++)
    {
        int pos=all[i].first;
        int need=all[i].second;
        for(int k=pos;k<n;k++)
        {
            if(a[k]<need)
            {
                counter++;
            }
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 18420
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    string S; cin >> S;
    string T = "AKIHABARA";
    int i = 0;
    for (int j = 0; j < T.size(); j++) {
        if (i < S.size() && S[i] == T[j]) {
            i++;
        } else if (T[j] == 'A') {
        } else {
            goto FAIL;
        }
    }
    if (i != S.size()) goto FAIL;
    cout << "YES\n"; return 0;
    FAIL: cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;

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

const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int h[maxn];
ll cal(ll a,ll b)
{
    return a/b + (a%b!=0);
}
int n,a,b;
bool check(ll mid)
{
    ll ned=0;
    for(int i=1;i<=n;i++)
    {
        if(cal(h[i],b)<=mid) continue;
        else
        {
            ll tt = h[i] - 1LL*mid*b;
            ned += cal(tt,a-b);
        }
        if(ned>mid) return false;
    }
    return ned<=mid;
}
int main() {
    //freopen(".in", "r", stdin);
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++) scanf("%d",&h[i]);
    ll l=1,r=100000000000000LL;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        if(check(mid)) r=mid-1;
        else l=mid+1;
    }
    printf("%lld\n",l);
    return 0;
}



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

int main() {
  int N, ans;
  cin >> N;
  vector<int>a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (a.at(a.at(i)-1) == i+1) {
      ans++;
    }
  }
  cout << ans/2;
}

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

int main(){
    vector<vector<int>> r;
    r = vector<vector<int>>(5, vector<int>(5,-1));
    for(int i=0; i<3; i++){
        int a, b;  cin >> a >> b;
        r[a][b] = 1;
        r[b][a] = 1;
    }

    vector<int> v(4);
    v[0] = 1; v[1] = 2; v[2] = 3; v[3] = 4;
    do{
        bool flag = true;
        for(int i=0; i<3; i++){
            if(r[v[i]][v[i+1]] == -1){
                flag = false;
            }
        }
        if(flag == true){
            cout << "YES" << endl;
            return 0;
        }
    }while(next_permutation(v.begin(), v.end()));

    cout << "NO" << endl;
}

Measured memory_bytes: 256
def main():
    n, k, s = map(int, input().split())
    if k == 0:
        if s != 10**9:
            ans = [10**9]*n
        else:
            ans = [1]*n
    else:
        if s == 10**9:
            ans = ([s]*k)+([1]*(n-k))
        else:
            ans = [s]*(k)+[10**9]*(n-k)
    print(*ans)


main()


Measured memory_bytes: 6652
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
	IOS;
	int n,k;
	cin>>n>>k;
	int r,s,p;
	cin>>r>>s>>p;
	int dp[3][n];
	memset(dp,0,sizeof(dp));
	string t;
	cin>>t;
	for(int i=0;i<n;i++){
		if(t[i]=='p'){
			if(i<k){
				dp[0][i]=0;
				dp[1][i]=s;
				dp[2][i]=0;
			}
			else{
				dp[0][i]=max(dp[1][i-k],dp[2][i-k]);
				dp[1][i]=max(dp[0][i-k],dp[2][i-k])+s;
				dp[2][i]=max(dp[0][i-k],dp[1][i-k]);	
			}
		}
		else if(t[i]=='r'){
			if(i<k){
				dp[0][i]=0;
				dp[1][i]=0;
				dp[2][i]=p;
			}
			else{
				dp[0][i]=max(dp[1][i-k],dp[2][i-k]);
				dp[1][i]=max(dp[0][i-k],dp[2][i-k]);
				dp[2][i]=max(dp[0][i-k],dp[1][i-k])+p;	
			}
		}
		else{
			if(i<k){
				dp[0][i]=r;
				dp[1][i]=0;
				dp[2][i]=0;
			}
			else{
				dp[0][i]=max(dp[1][i-k],dp[2][i-k])+r;
				dp[1][i]=max(dp[0][i-k],dp[2][i-k]);
				dp[2][i]=max(dp[0][i-k],dp[1][i-k]);	
			}
		}
	}
	int ans=0;
	for(int i=n-1;i>=n-k;i--){
		ans+=max({dp[0][i],dp[1][i],dp[2][i]});
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2816
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		if (n % 2 == 0) {
			pr.println(0.5);
		} else {
			pr.println((double)(n / 2 + 1) / n);
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

int main() {
	int n,m;cin >> n >> m;
	vector<int> v(n,0);
	for(int i=0;i<m;++i){
		int a,b; cin>> a>>b;
		v[a-1] += 1;
		v[b-1] += 1;
	}
	for(int j=0;j<n;++j){
		cout << v[j] << endl;
	}
	return 0;
}

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

using namespace std;

const int nax=3333;
double dp[nax][nax];

int main()
{
    int n; cin>>n;
    double a[nax];
    for(int i=1;i<=n;i++) cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            dp[i][j]=dp[i-1][j]*(1-a[i]);
            if(j>0) dp[i][j]+=dp[i-1][j-1]*a[i];
        }
    }
    double res=0;
    for(int i=0;i<=n;i++)
    {
        if(i*2>n) res+=dp[n][i];
    }
    cout<<fixed<<setprecision(15)<<res;
    return 0;
}


Measured memory_bytes: 80128
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
//typedef pair<ll,ll> p; 
int main()
{
     int x,y,z;
     cin>>x>>y>>z;
     cout<<z<<" "<<x<<" "<<y<<endl;
}

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

const int64_t MOD = 1000000007;

long long powMod(long long x, long long n, long long mod = 1000000007) {
    long long res = 1LL;
    while(n > 0) {
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return res;
}

long long invMod(long long n, long long mod = 1000000007) {
    return powMod(n, mod - 2, mod);
}

function<int64_t(int64_t, int64_t)> nCk = [&](int64_t N, int64_t K) -> int64_t {
    if(K < 0 || N < K) return 0LL;
    int64_t ret = 1LL;
    for(int64_t i = 1; i <= K; ++i) {
        ret *= N--;
        ret %= MOD;
        ret *= invMod(i);
        ret %= MOD;
    }
    return ret;
};

int main() {
    int64_t n, a, b;
    cin >> n >> a >> b;
    int64_t ans = powMod(2, n) - 1 - nCk(n, a) - nCk(n, b) + 10 * MOD;
    cout << ans % MOD << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#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 INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

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

    vector<int> N(Q,0);
    REP(i,Q){
        cin >> N[i];
    }
    //入力終わり

    REP(i,Q){
        int ans=0;
        while(1){
            int n=N[i];
            int a[7];
            REP(j,7){
                a[j]=n%10;
                n=n/10;
            }
            //桁ごとに分離、桁数t

            if(N[i]/10==0)break;
            //一桁の時break;

            int maxi=0;
            FOR(t,1,6){
                int b=0,c=0;
                REP(j,t){
                    int a1=a[j];
                    REP(k,j){
                        a1=a1*10;
                    }
                    b+=a1;
                }
                FOR(j,t,7){
                    int a2=a[j];
                    REP(k,j-t){
                        a2=a2*10;
                    }
                    c+=a2;
                }
                maxi=max(maxi,b*c);
            }
            N[i]=maxi;
            ans++;
            //t-1通り計算して最大値が次のN[i]    
        }
        cout << ans << endl;
    }

    return 0;
}

//AOJ2015 ?:??:??


Measured memory_bytes: 3140
#define _CRT_SECURE_NO_WARNINGS

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-6
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 350

using namespace std;

const int INF = 1e9;
const int N = 110000;

int n;
vector<int> g[N];
int known[N], val[N];
int K;
int l[N], r[N];
int used[N];
int known_parity[N][2];
int shit;

vector<int> order;
int par[N];

void dfs(int v)
{
	used[v] = 1;

	l[v] = -1e9;
	r[v] = 1e9;
	for (int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i];
		if (used[to])
			continue;
		dfs(to);
		par[to] = v;
		if (known_parity[to][0])
			known_parity[v][1] = 1;
		if (known_parity[to][1])
			known_parity[v][0] = 1;
		l[v] = max(l[v], l[to] - 1);
		r[v] = min(r[v], r[to] + 1);
	}
	
	if (known[v] == 1)
	{
		l[v] = max(l[v], val[v]);
		r[v] = min(r[v], val[v]);
		known_parity[v][val[v] % 2] = 1;
	}

	if (known_parity[v][0] == 1 && known_parity[v][1] == 1)
	{
		shit = 1;
	}

	if (l[v] > r[v])
		shit = 1;

	order.push_back(v);
}

int ans[N];

int solve_val(int v, int par)
{
	if (par == 0)
	{
		return l[v];
	}
	l[v] = max(l[v], ans[par] - 1);
	r[v] = min(r[v], ans[par] + 1);
	while (l[v] % 2 == ans[par] % 2)
		++l[v];
	return l[v];
}

int main(){
	//freopen("fabro.in","r",stdin);
	//freopen("fabro.out","w",stdout);
	//freopen("F:/in.txt", "r", stdin);
	//freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	cin >> K;
	for (int i = 1; i <= K; i++)
	{
		int a, b;
		cin >> a >> b;
		known[a] = 1;
		val[a] = b;
	}

	dfs(1);

	if (shit)
	{
		cout << "No" << endl;
		return 0;
	}

	reverse(order.begin(), order.end());

	cout << "Yes" << endl;

	for (int i = 0; i < order.size(); i++)
	{
		int v = order[i];
		if (par[v] == 0)
		{
			ans[v] = solve_val(v,par[v]);
		}
		else
		{
			ans[v] = solve_val(v, par[v]);
		}
	}

	for (int i = 1; i <= n; i++)
	{
		cout << ans[i] << endl;
	}

	cin.get(); cin.get();
	return 0;
}

Measured memory_bytes: 15352
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main(){
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a*b>c*d)
		cout<<a*b;
	else
		cout<<c*d;
	return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        if(s[i] % 2  == i % 2)ans++;
    }
    cout << min(n-ans,ans) << endl;
}

Measured memory_bytes: 512
n = int(input())
l = []
for _ in range(n-1):
    l.append([int(i) for i in input().split()])
for j in range(n):
    l_ = l[j:]
    c = 0
    for i in range(n-1-j):
        if c <= l_[i][1]:
            c = l_[i][1]
        elif (c % l_[i][2] != 0):
            c = (c // l_[i][2] + 1) * l_[i][2]
        else:
            c = (c // l_[i][2]) * l_[i][2]
        c += l_[i][0]
    print(c)

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

typedef long long ll;
typedef pair<ll ,ll> pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll MOD = 1000000007;
const ll INF = 1e18;//1*10^18

ll powll(ll a,ll n){//O(log n)
  ll res=1;
  while(n>0)
  {
    if(n & 1)//(n & 1)=(n % 2 !=0)
    {
      res=res*a;
    }
    a=a*a;
    n>>=1;//(n & 1)=(n % 2 !=0)
  }
  return res;
}

ll modpow(ll a,ll n,ll mod)//O(log n)
{
  ll res=1;
  while(n>0)
  {
    if(n & 1)//(n & 1)=(n % 2 !=0)
    {
      res=res*a%mod;
    }
    a=a*a%mod;
    n>>=1;//(n>>=1)=(n/2)
  }
  return res;
}

int ReturnDigit(ll num)
{
  string number=to_string(num);
  return number.length();
}

const ll MAX=1e4;
long long fac[MAX], finv[MAX], inv[MAX];

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

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

int main() {
  // srand((unsigned int)time(NULL));//--> rand()
  ll i,j,k,l;
  ll num=0,max=0;
  string s;
  cin >>s;
 
 rep(i,s.length())
 {
   if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')
   {
     num+=1;
   }else
   {
    if(max<num)
    {
      max=num;
    }
     
    num=0;  
   }    
 }

if(max<num)
{
  max=num;
}
  cout<< max <<endl;
}

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

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;


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

    ll n, a, b;
    cin >> n >> a >> b;
    ll posl, pre;
    for(ll i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        if(i == n - 2) pre = x;
        if(i == n - 1) posl = x;
    }
    ll res = abs(b - posl);
    if(n == 1) cout << res;
    else
    {
        if(abs(posl - pre) > res) res = abs(posl - pre);
        cout << res;
    }

    return 0;
}


Measured memory_bytes: 256
n=input()
S=[range(1,14) for j in range(4)]
for i in range(n):
    ip=raw_input().split()
    if ip[0]=='S':
        S[0].remove(int(ip[1]))
    elif ip[0]=='H':
        S[1].remove(int(ip[1]))
    elif ip[0]=='C':
        S[2].remove(int(ip[1]))
    else :
        S[3].remove(int(ip[1]))
for i in S[0]:
   print 'S '+str(i)
for i in S[1]:
   print 'H '+str(i)
for i in S[2]:
   print 'C '+str(i)
for i in S[3]:
   print 'D '+str(i)

Measured memory_bytes: 6460
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    int ans=1;
    for(int i=0;i<n;i++){
        ans*=3;
    }
    int k=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2==0)k*=2;
    }
    cout<<ans-k<<endl;
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  vector<int>a(3);
  for(int i=0;i<s.size();i++)
    a.at(s.at(i)-97)++;
  bool ans=true;
  if(abs(a.at(0)-a.at(1))>1||abs(a.at(1)-a.at(2))>1||abs(a.at(0)-a.at(2))>1)
    ans=false;
  cout << (ans?"YES":"NO") << endl;
  return 0;
}

Measured memory_bytes: 3728
def choose(n, r, M):
    x = 1
    y = 1

    for i in range(r):
        x = x * (n - i) % M
        y = y * (i + 1) % M
    res = x * pow(y, M-2, M) % M
    return res

n, a, b = map(int, input().split())
M = 10 ** 9 + 7

print((pow(2, n, M) - 1 - choose(n, a, M) - choose(n, b, M)) % M)


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

int main()
{
    string s,t;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(i%2 == 0){
            t += s[i];
        }
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<double>   vd;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define log2ll(x) (63 - __builtin_clzll(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;



int main(){

	int n,m;
	sf1(n);
	map<string,int> mp;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;

		mp[s]++;
	}
	sf1(m);
	for (int i = 0; i < m; ++i)
	{
		string s;
		cin >> s;
		mp[s]--;
	}

	int ans = 0;
	for(auto p: mp){
		ans = max(ans,p.ss);
	}

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

	

}

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

#define ll long long

int t,n;

void solve() {
	cin>>n;
	vector<ll> a(n);
	for(int i=0;i<n;++i)
		cin>>a[i];
	ll cnt=1,check,tmp=1,ans=0;
	sort(a.rbegin(),a.rend());
	check=a[0];ans=0;
	int i=0,ok=1;
	while(--n) {
		if(ok<2) {
			++ok;
		} else {
			ok=1;
			++i;
		}
		ans+=a[i];
	}
	cout<<ans<<'\n';
}

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

	//cin >> t;
	//while(t--) 
		solve();
	//return 0;
}


Measured memory_bytes: 4768
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<=c&&b<=c){
		cout<<a+b<<endl;
	}
	else if(a<=b&&c<=b){
		cout<<a+c<<endl;
	}
	else if(c<=a&&b<=a){
		cout<<c+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
 
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;
typedef vector<pii> vp;

#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int w, h;
int p[112345], q[112345];

int main() {
	cin >> w >> h;
	REP(i, w) scanf("%d", p + i);
	REP(i, h) scanf("%d", q + i);
	
	priority_queue<pii, vector<pii>, greater<pii> > pq;
	REP(i, w) pq.push(pii(p[i], 0));
	REP(i, h) pq.push(pii(q[i], 1));
	
	
	int cnt[2] = {};
	ll ans = 0;
	
	while (!pq.empty()) {
		pii now = pq.top(); pq.pop();
		
		int cost = now.first;
		int pat = now.second;
		
		if (pat == 0) {
			ans += (ll)cost * (h + 1 - cnt[1]);
			cnt[0]++;
		}
		else {
			ans += (ll)cost * (w + 1 - cnt[0]);
			cnt[1]++;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>
#define N 500000

int cnt = 0;

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int main(){
  int i,n,A[N];
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i = 0; i < n-1 ; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[i],cnt);
  return 0;
}

void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,L[N],R[N],k;
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0; i < n1;i++){
    L[i] = A[left + i];
  }
  for(i = 0; i < n2;i++){
    R[i] = A[mid + i];
  }
  L[n1] = 999999999;
  R[n2] = 999999999;
  i = 0;
  j = 0;
  for(k = left; k < right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      cnt++;
    }
    else {
      A[k] = R[j];
      j++;
      cnt++;
    }
  }
}

void mergeSort(int *A,int left,int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 5652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
using namespace std;
using ll = long long;
void self_max(int &a,int b){
  a = max(a,b);
}

int main(){
  int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
  int key = e-a;
  if(k >= key) cout << "Yay!" << endl;
  else cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256