akhauriyash/Code-Regression huggingface dataset:
////////////////////////////////////////////////////
                    //                                                //
                    //  For her who keeps the fire kindling in me...  //
                    //                                                //
                    ////////////////////////////////////////////////////

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
// import java.util.Scanner;
// import java.util.Arrays;
// import java.util.ArrayList;
// import java.util.Collections; 
// import java.util.StringTokenizer;
import java.util.*;
import java.lang.Math;
import java.awt.Point;

import java.awt.geom.*;

public class Main {

    public static void main(String args[]) {
        try {
            FastReader s = new FastReader();
            BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
            int i, j;
            int m, n, t, max, k, x, y, min, correct_ans, vert, num, size, local_ans, global_ans;
            long a, b, sum;


            n = s.nextInt();
            m = s.nextInt();
            
            // a = s.nextLong();
            // b = s.nextLong();
           
            w.write((int)Math.ceil((float)n/m)+"\n");
            w.close();


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

// ========================================### FAST IO ###=========================================//
class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

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

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

    Double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}
// ====================================================================================================//

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

int main()
{
    char a[10];
    int ans = 0;

    scanf("%s", a);
    for (int i = 0; i < 6; i++) {
        if (a[i] == '1') ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
x = int(input())

if 400 <= x <= 599:
    print(8)
if 600 <= x <= 799:
    print(7)
if 800 <= x <= 999:
    print(6)
if 1000 <= x <= 1199:
    print(5)
if 1200 <= x <= 1399:
    print(4)
if 1400 <= x <= 1599:
    print(3)
if 1600 <= x <= 1799:
    print(2)
if 1800 <= x <= 1999:
    print(1)




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

int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  for (int i = 0; i < N; i++) cin >> p[i];
  
  sort(p, p + N);
  int count = 0;
  for (int i = 0; i < K; i++){
    count += p[i];
  }
  cout << count << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//入力
ll n;
string c;

int main(){
    cin >> n;
    cin >> c;
    vector<ll>w,r;
    rep(i,n){
        if(c[i]=='W'){
            w.push_back(i);
        }
    }
    for(int i=n-1;i>=0;i--){
        if(c[i]=='R'){
            r.push_back(i);
        }
    }
    ll ans = 0;
    r.push_back(-1);
    w.push_back(-1);
    rep(i,n){
        if(r[i]==-1)break;
        if(w[i]==-1)break;
        if(w[i]<r[i])ans++;
        else break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5924
import java.util.*;
import java.io.*;

//双方向連結リスト構造

public class Main {

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

		int loop = in.nextInt();
		MyLinkedList list = new MyLinkedList();

		for(int i = 0; i < loop; i++) {
			int odr = Integer.parseInt(in.next());

			switch(odr) {
				case 0:
					int x = Integer.parseInt(in.next());
					list.add(x);
					break;

				case 1:
					int d = Integer.parseInt(in.next());
					list.move(d);
					break;

				case 2:
					list.remove();
					break;
			}
		}

		ArrayList<Integer> dumpArr = list.dump();
		PrintWriter out = new PrintWriter(System.out);
		for(Integer value : dumpArr) {
			out.println(value);
		}
		out.flush();
		in.close();
	}

}

class ListNode{
	int value;
	ListNode prv, next;

	ListNode(int v){
		value = v;
		prv = this;
		next = this;
	}
}

class MyLinkedList{
	private ListNode END, NOW;

	MyLinkedList(){
		END = new ListNode(0);
		NOW = END; //カーソル
	}

	void add(int x) {
		ListNode NEW = new ListNode(x);

		//ポインタ切替処理
		//先に新規ノードのポインタを定義させる
		NEW.next = NOW;
		NEW.prv = NOW.prv;

		//次に既存のノードのポインタを切り替える
		NEW.prv.next = NEW;
		NOW.prv = NEW;

		//カーソル移動
		NOW = NEW;
	}

	void remove() {
		//ポインタ切替処理
		NOW.prv.next = NOW.next;
		NOW.next.prv = NOW.prv;

		//カーソル移動
		NOW = NOW.next;
	}

	void move(int d) {

		if(d > 0) {
			for(int i = 0; i < d; i++) {
				NOW = NOW.next;
			}
		}else {
			for(int i = 0; i > d; i--) {
				NOW = NOW.prv;
			}
		}
	}

	ArrayList<Integer> dump() {
		ArrayList<Integer> dumpArr = new ArrayList<>();
		ListNode now = END.next;

		while(now != END) {
			dumpArr.add(now.value);
			now = now.next;
		}
		return dumpArr;
	}
}


Measured memory_bytes: 166580
a = input()
li = []
for s in a:
  li.append(s)

count = 0
for i in range(1,4):
  if li[i] == li[i-1]:
    count += 1
    if count == 2:
      break
  else:
    count = 0

if count >= 2:
  print("Yes")
else:
  print("No")


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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int x[100009];
int y[100009];
int z[100009];

int main() {
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      if (a-1 >= 0) {
         x[a-1]++;
      }
      y[a]++;
      z[a+1]++;
   }

   int Max = -1;
   for (int i = 0; i <= 100000; i++) {
      int t = x[i] + y[i] + z[i];
      Max = max(Max, t);
   }

   cout << Max << endl;

   return 0;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  map<string, int> mp;
  for(int i = 0; i < k; i++){
    int d;
    cin >> d;
    for(int z = 0; z < d; z++){
      string a;
      cin >> a;
      mp[a] = 1;
    }
  }
  int count = 0;
  for(int i = 1; i <= n;i++){
    if (mp.find(std::to_string(i)) == mp.end())
    {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3700
s = list(input())
N = len(s)

ans = [-1,-1]
for i in range(N):
  if(i != 0):
    if(s[i-1]==s[i]): 
      ans = [i,i+1]
      break
  if(i >= 2):
    if(s[i-2]==s[i]):
      ans = [i-1,i+1]
      break
      
print(ans[0],ans[1])

Measured memory_bytes: 3956
#include  <stdio.h>


	int main(void)
	{
		int a,i, count = 0;
		char yourinput[1024],check;
		int go=0;

		scanf("%d", &a);
		scanf("%s", yourinput);
		check = 'I';

		for (i = 0; yourinput[i] != '\0'; i++)
		{
			if (yourinput[i] == check)
			{
				count++;
			}
			else {
				count--;
			}
			if (go < count) {
				go = count;
			}
		}

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

		return 0;

	}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long int dp[3001][3001][2];
long long int arr[3001];
long long int func(long long int start,long long int end,long long int turn)
{
	if(start>end)
		return 0;
	else if(start==end)
	{
		if(turn==0)
		dp[start][end][turn]=arr[start];
	    else
	    dp[start][end][turn]=-arr[start];
		return dp[start][end][turn];
	}
	else if(start<end)
	{
	if(dp[start][end][turn]!=1000000000000007)
      return dp[start][end][turn];
    long long int ans1,ans2,ans;
    if(turn==0)
    {
    ans1=arr[start]+func(start+1,end,1-turn);
    ans2=arr[end]+func(start,end-1,1-turn);
    }
    else
    {
    ans1=func(start+1,end,1-turn)-arr[start];
    ans2=func(start,end-1,1-turn)-arr[end];
    }
    if(turn==0)
    ans=max(ans1,ans2);
    else
    ans=min(ans1,ans2);
    dp[start][end][turn]=ans;
    return ans;
    }
}
int main()
{
	long long int n;
	scanf("%lld",&n);
	long long int i,ans,j,k;
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			{
				dp[i][j][0]=1000000000000007;
				dp[i][j][1]=1000000000000007;
			}
	for(i=0;i<n;i++)
		scanf("%lld",&arr[i]);
    ans=func(0,n-1,0);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 141056
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int cnt = Integer.parseInt(scan.next());
        int total = Integer.parseInt(scan.next());
        //int c = Integer.parseInt(scan.next());
//        int cnt = 0;
//        while(h>0) {
//            h = h-a;
//            cnt++;
//        }
        if(cnt*500 >= total) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll x; cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3640
/*
 * src.cpp
 *
 *  Created on: 2016/07/26
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

bool c[3];

int main(){
	c[0]=true;
	char a,b;
	while(scanf("%c,%c",&a,&b)!=EOF){
		swap(c[a-'A'],c[b-'A']);
	}
	REP(i,3){
		if (c[i]) printf("%c\n",'A'+i);
	}
	return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int digit(int n) {
    int ret = 0;
    while(n > 0) {
        ret++;
        n /= 10;
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<vector<int>> vec(10,vector<int>(10));
    for(int i = 1;i <= N;i++) {
        int A = digit(i);
        int B = i % 10;
        int C = i / pow(10,A - 1);
        vec.at(B).at(C)++;
    }
    int ret = 0;
    for(int i = 0;i < 10;i++) {
        for(int j = 0;j < 10;j++) {
            ret += vec[i][j] * vec[j][i];
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
n= int(input())
A = list(map(int, input().split()))

zero = 0
if zero in A:
    print("0")
else:
    for i in range(n):
    
        temp = A[i]
        if i ==0:
            kakeru = temp
        else:
            kakeru = kakeru*temp
        if kakeru >10**18:
            kakeru = -1
            break
    
    print(kakeru)

Measured memory_bytes: 21796
import sys
readline = sys.stdin.readline

import numpy as np

N,K = map(int,readline().split())
A = np.sort(np.array(readline().split(), dtype = int))
F = np.sort(np.array(readline().split(), dtype = int))[::-1]

# X秒で完食できるか二分探索

ng = -1
ok = F[0] * A[-1]

def isOk(x):
  return A.sum() - np.minimum(A, x // F).sum() <= K
  
while abs(ok - ng) > 1:
  mid = abs(ok + ng) // 2
  if isOk(mid):
    ok = mid
  else:
    ng = mid
    
print(ok)



Measured memory_bytes: 53224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef bitset<305> bs;

const int MOD = 998244353;

bs matrix[305];

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    b*=b;
    b%=m;
    e/=2;
  }
  return r;
}

void solve() {
  int r, c;
  cin >> r >> c;
  for(int i = 0; i < r; i++) {
    for(int j = 0; j < c; j++) {
      int t;
      cin >> t;
      if(t) matrix[i].set(j);
    }
  }
  int rank = 0;
  for(int j = 0; j < c; j++) {
    bool found = false;
    for(int i = rank; i < r; i++) {
      if(matrix[i][j]) {
        found = true;
        if(i != rank) swap(matrix[i], matrix[rank]);
      }
    }
    if(found) {
      for(int i = rank+1; i < r; i++) {
        if(matrix[i][j]) matrix[i] ^= matrix[rank];
      }
      rank++;
    }
  }
  ll ret = modpow(2, r+c-1, MOD);
  ret -= modpow(2, r+c-1-rank, MOD);
  ret += MOD;
  cout << ret%MOD << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


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(void){
    
    int X;
    cin >> X;
    rep(i,8){
        int v = 200;
        if((400+v*i <= X) && (599+v*i >= X)){
            cout << 8 - i << endl;
            break;
        } 
    }

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <math.h> 

using namespace std;



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

	int n, k, c, i, j, ans, last, ct;
	string s;
	cin >> n >> k >> c >> s;
	vector<int> ll(n, -1), rr(n, -1);
	
	ct = 0; last = -n - n;
	for (i = 0; i < n; i++) {
		if ((ct <= k) && (s[i] == 'o') && (i - last >= c + 1)) {
			ll[i] = ct++;
			last = i;
		}
	}

	ct = 0; last = n * 3;
	for (i = n - 1; i >= 0; i--) {
		if ((ct <= k) && (s[i] == 'o') && (last - i >= c + 1)) {
			rr[i] = k - 1 - ct;
			ct++;
			last = i;
		}
	}

	for (i = 0; i < n; i++) {
		if ((ll[i] == rr[i]) && (ll[i] != -1)) cout << i + 1 << "\n";
	}

	return 0;
}




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

using namespace std;

#define IOS ios_base::sync_with_stdio(0),cin.tie(0)
#define vi vector<int> vi;
typedef long long ll;


int main(){
	IOS;
	int n;
	cin>>n;
	cout<<((n/500)*1000 + ((n%500)/5) * 5)<<"\n";
	
	
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n = int(input())
li = list(map(int,input().split()))
cntr = 0

for i in range(n - 2):
    li_tmp = li[i : (i + 3)]
    if li_tmp[1] != max(li_tmp) and li_tmp[1] != min(li_tmp):
        cntr += 1
print(cntr)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

vector<int> getDegs(int h,int m,int s){
  vector<int> res({h,m,s});
  res[1] = (res[1] - res[0] + 60)%60;
  res[2] = (res[2] - res[0] + 60)%60;
  res[0] = 0;
  return res;
}


int toSec(int h,int m,int s){return s + 60*m + 60*60*(h/5);}
int toSec(vector<int> a){return toSec(a[0],a[1],a[2]);}
bool can(int hh,int mm,int ss){return hh%5 == mm/12;}

vector<vector<int> > calcSameTimes(vector<int> a){
  vector<vector<int> > res; 
  for(int h=0;h<60;h++)
    for(int m=0;m<60;m++)
      for(int s=0;s<60;s++){
        if(!can(h,m,s))continue;
        if(a == getDegs(h,m,s)) res.push_back(vector<int>({h,m,s}));
      }
  return res;
}

vector<vector<int> > calcSameTimes(int h,int m,int s){
  vector<int> a = {h,m,s}; sort(a.begin(),a.end());
  vector<vector<int> > res; 
  do{
    vector<vector<int> > tmp = calcSameTimes(getDegs(a[0],a[1],a[2]));
    for(vector<int> t:tmp) res.push_back(t);
  } while(next_permutation(a.begin(),a.end()));
  sort(res.begin(),res.end());
  res.erase(unique(res.begin(),res.end()),res.end());
  return res;
}

int n;
vector<vector<vector<int> > > times;
vector<int> calcTime(int h,int m,int s){
  vector<int> res;
  int mx = -1;
  for(int i=0;i<n;i++){
    vector<int> tmp;
    int mn = INF;
    for(vector<int> &t:times[i]){
      int a = toSec(h,m,s);
      int b = toSec(t[0],t[1],t[2]);
      if(b < a || mn <= b - a) continue;
      mn = b - a;
      tmp = t;
      break;
    }
    if(mn == INF) return vector<int>();
    if(mx < mn) mx = mn, res = tmp;
  }
  return res;
}

signed main(){
  while(1){
    cin>>n;
    if(!n) break;
    times.clear();
    times.resize(n);
    for(int i=0;i<n;i++){
      int h,m,s;
      cin>>h>>m>>s;
      times[i] = calcSameTimes(h,m,s);
    }
    
    vector<int> from,to;
    int mn = INF;
    for(int h=0;h<60;h++)
      for(int m=0;m<60;m++)
        for(int s=0;s<60;s++){
          if(!can(h,m,s))continue;
          vector<int> a = {h,m,s};
          vector<int> b = calcTime(h,m,s);
          if(b.empty()) continue;
          int as = toSec(h,m,s);
          int bs = toSec(b[0],b[1],b[2]);
          assert(bs >= as);
          if(mn > bs - as) mn = bs - as, from = a, to = b;
        }
  
    printf("%02lld:%02lld:%02lld ",from[0]/5,from[1],from[2]);
    printf("%02lld:%02lld:%02lld\n",to[0]/5,to[1],to[2]);
  }
  return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, d;
    cin >> n >> d;
    d *= d;
    ll ans = 0;
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        ll cd = x * x + y * y;
        if (cd <= d) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<ctime>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;

int main() {
	ll a, b, c, x, y, ans;
	cin >> a >> b >> c >> x >> y;
	if (c + c <= a + b) {
		ans = min(x, y) * c * 2;
		if (x > y) {
			ans += (x - y) * min(c + c, a);
		}
		else if (y > x) {
			ans += (y - x) * min(c + c, b);
		}
	}
	else {
		ans = a * x + b * y;
	}
	cout << ans << "\n";
	return 0;
} 


Measured memory_bytes: 256
public class Main {

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    protected static Answer calc0(String input) {
        final int[] ia = split(input);

        final int a = ia[0];
        final int b = ia[1];

        Answer answer = new Answer();

        answer.d = a / b;
        answer.r = a % b;
        answer.f = (double) a / (double) b;

        return answer;
    }

    protected static String calc(String input) {
        return String.valueOf(calc0(input));
    }

    private static int[] split(String s) {
        final String[] s0 = s.split(" ");
        int[] ia = new int[s0.length];

        for (int i = 0; i < s0.length; i++) {
            ia[i] = Integer.parseInt(s0[i]);
        }

        return ia;
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }

    static class Answer {
        int d;
        int r;
        double f;
        java.text.Format df = new java.text.DecimalFormat("0.00000");

        @Override
        public String toString() {
            return d + " " + r + " " + df.format(f);
        }
    }
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<ll, ll> ii;
const int mod = 1e9+7;
const ll INF = 1e18;
const int inf = 1e9;

void solve()
{
  int n,k; cin>>n>>k;
  vector<vector<int>> td(n);
  rep(i,n) {
    int t,d; cin>>t>>d;
    td[t-1].push_back(d);
  }
  vector<ll> x;
  vector<ll> y;
  rep(i,n) {
    sort(td[i].rbegin(),td[i].rend());
    int sz = (int)(td[i].size());
    rep(j,sz) {
      if (j==0) x.push_back(td[i][j]);
      else y.push_back(td[i][j]);
    }
  }
  sort(x.rbegin(),x.rend());
  sort(y.rbegin(),y.rend());

  vector<ll> xsum;
  vector<ll> ysum;
  xsum.push_back(0); ysum.push_back(0);
  for (auto& t: x) {
    xsum.push_back(xsum.back() + t);
  }
  for (auto& t: y) {
    ysum.push_back(ysum.back() + t);
  }
  int xl = (int)(xsum.size());
  int yl = (int)(ysum.size());
  ll ans = 0;
  for (int i=1; i<min(k+1,xl); i++) {
    if (k-i>=yl) continue;
    ans = max(ans, xsum[i] + ysum[max(k-i,0)] + (ll)i*i);
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 8052
// Problem Code: abc170_a

#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int five_variables(vector<int>& x) {
	return 15 - accumulate(x.begin(), x.end(), 0);
}

int main() {
	vector<int> x(5);
	for (int i = 0; i < x.size(); i++)
		cin >> x[i];
	cout << five_variables(x);
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

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

  int32_t N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  vector<int> early(K);
  int i = 0;
  int cnt = 0;
  while (i < N && cnt < K) {
    if (S[i] == 'o') {
      early[cnt] = i;
      cnt++;
      i += (C + 1);
    } else {
      i++;
    }
  }
  vector<int> late(K);
  i = N - 1;
  cnt = K - 1;
  while (i >= 0 && cnt >= 0) {
    if (S[i] == 'o') {
      late[cnt] = i;
      cnt--;
      i -= (C + 1);
    } else {
      i--;
    }
  }

  for (i = 0; i < K; i++) {
    if (early[i] == late[i]) {
      cout << early[i] + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
const int MAX_N = 2e5 + 5;
const int INF = 1e9 + 7;
int pos[MAX_N], n;
typedef pair<int, int> pii;
struct Segment_Tree {
    int seg[MAX_N << 2];
    void push_up(int rt) {
        seg[rt] = min(seg[rt << 1], seg[rt << 1 | 1]);
    }
    void Build(int l, int r, int rt) {
        if (l == r) {
            seg[rt] = INF;
            return;
        }
        int m = (l + r) / 2;
        Build(lson);
        Build(rson);
        push_up(rt);
    }
    void Update(int pos, int c, int l, int r, int rt) {
        if (l == r) {
            seg[rt] = c;
            return;
        }
        int m = (l + r) / 2;
        if (pos <= m) Update(pos, c, lson);
        else Update(pos, c, rson);
        push_up(rt);
    }
    int Query(int L, int R, int l, int r, int rt) {
        if (L <= l && r <= R) return seg[rt];
        int m = (l + r) / 2, res = INF;
        if (L <= m) res = min(res, Query(L, R, lson));
        if (R > m) res = min(res, Query(L, R, rson));
        return res;
    }
} ST[2];
struct cmp {
    bool operator () (const pii &x, const pii &y) const {
        return ST[x.first % 2].Query(x.first, x.second, 1, n, 1) > ST[y.first % 2].Query(y.first, y.second, 1, n, 1);
    }

};
priority_queue<pii, vector<pii>, cmp> que;
int main() {
    int x, l, r, p, q;
    scanf("%d", &n);
    ST[0].Build(1, n, 1);
    ST[1].Build(1, n, 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &x);
        pos[x] = i;
        ST[i % 2].Update(i, x, 1, n, 1);
    }
    que.push(make_pair(1, n));
    while (!que.empty()) {
        l = que.top().first;
        r = que.top().second;
        que.pop();
        p = ST[l % 2].Query(l, r, 1, n, 1);
        q = ST[(l + 1) % 2].Query(pos[p], r, 1, n, 1);
        //printf("%d %d %d %d\n", p, q, pos[p], pos[q]);
        if (l < pos[p] - 1) que.push(make_pair(l, pos[p] - 1));
        if (pos[p] + 1 < pos[q] - 1) que.push(make_pair(pos[p] + 1, pos[q] - 1));
        if (pos[q] + 1 < r) que.push(make_pair(pos[q] + 1, r));
        printf("%d %d%c", p, q, que.empty() ? '\n' : ' ');
    }
}


Measured memory_bytes: 8824
n,m = map(int,input().split())
h = list(map(int,input().split()))  #hの要素はn個
#全て良い道にしておく
li = [1 for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    if(h[a-1] < h[b-1]):
        li[a-1] = 0
    elif(h[b-1] < h[a-1]):
        li[b-1] = 0
    elif(h[a-1] == h[b-1]):
        li[a-1] = 0
        li[b-1] = 0
    
c=0
for i in range(len(li)):
    if(1 == li[i]):
        c += 1

print(c)


















Measured memory_bytes: 20028
#include <iostream>

using namespace std;

#define MAX 1000500
 
bool prime[MAX];
 
void is_prime(){
    fill(prime,prime+MAX,true);
    prime[0] = prime[1] = false;
     
    for(int i = 2 ; i*i < MAX ; i++){
        if(prime[i]){
            for(int j = i*i ; j < MAX ; j += i){
                prime[j] = false;
	    }
	}
    }
}
 
int main(){
    int a,d,n;
     
    is_prime();
     
    while(cin >> a >> d >> n , a+d+n){
        int cnt = 0,i;
         
        for(i = a ; i < MAX ; i += d){
            if(prime[i]) cnt++;
            if(cnt == n) break;
        }
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

constexpr int lim = 1e3, mod = 1e9+7;
int h, w;
char grid[lim+1][lim+1];
ll dp[lim+1][lim+1];

int main(){
  cin >> h >> w;
  REP(y, h)REP(x, w){
    cin >> grid[y][x];
  }

  dp[0][0] = 1;

  REP(y, h)REP(x, w){
    if(y+1 < h && grid[y+1][x] == '.') 
      (dp[y+1][x] += dp[y][x]) %= mod;
    if(x+1 < w && grid[y][x+1] == '.') 
      (dp[y][x+1] += dp[y][x]) %= mod;
  }

  cout << dp[h-1][w-1] << endl;

  return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL N, A, B;
    cin >> N >> A >> B;

    LL res = N / (A + B) * A;
    N %= (A + B);
    cout << res + min(N, A) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int row,col,h,w,whitecells;     /*row:行 col:列*/
  scanf("%d %d",&row,&col);
  scanf("%d %d",&h,&w);
  whitecells = (row-h)*(col-w); 
  printf("%d",whitecells);
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if (A%3 == 0) System.out.println("Possible");
		else if (B%3 == 0) System.out.println("Possible");
		else if ((A+B)%3 == 0) System.out.println("Possible");
		else System.out.println("Impossible");
	}
}


Measured memory_bytes: 21844
from math import floor, ceil

A, B = map(int, input().split())

min1 = A/0.08
max1 = (A+0.9999999)/0.08
min2 = B/0.1
max2 = (B+0.9999999)/0.1

rangeMin = ceil(max(min1, min2))
rangeMax = floor(min(max1, max2))
if rangeMin > rangeMax:
    print(-1)
else:
    print(rangeMin)

Measured memory_bytes: 3064
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

vll adjlist[2005];
bool vis[2005];
int par[2005];
vll bfs(int node){
	memset(vis,0,sizeof vis);
	memset(par,-1,sizeof par);
	vis[node]=1;
	queue<int> q;
	q.push(node);
	vll sc;
	while(!q.empty()){
		int tp = q.front();
		//cout<<tp<<endl;
		q.pop();
		for(int i:adjlist[tp]){
			if(!vis[i]){
				q.push(i);
				par[i]=tp;
				vis[tp]=1;
			}
			else{
				if(i==node){
					int k=tp;
					while(k!=-1){
						sc.pb(k);
						k=par[k];
					}
					return sc;
				}
			}
		}
	}
	return sc;
}

void solve(){  
	pair<int,vll> ans=mp(hell,vector<int> (1));
	int n,m;
	cin>>n>>m;
	rep(i,0,m){
		int u,v;
		cin>>u>>v;
		adjlist[u].pb(v);
	}
	rep(i,1,n+1){
		vll cyc=bfs(i);
		if(cyc.empty()){
			continue;
		}
		ans=min(ans,mp(sz(cyc),cyc));
	}
	if(ans.F==hell){
		cout<<-1<<endl;
	}
	else{
		cout<<ans.F<<endl;
		for(int i:ans.S){
			cout<<i<<endl;
		}
	}
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int N;

	cin >> N;


	vi d(N);

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

	ll ans = 0;

	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			ans += d[i] * d[j];
		}
	}

	cout << ans << '\n';


	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=200000000000005LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<P,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
struct edge{
	ll x;
	ll y;
	bool operator<(const edge& e)const{
		return x+y<e.x+e.y;
	}
	bool operator>(const edge& e)const{
		return x+y>e.x+e.y;
	}


};
struct road{ll cost;int to;};
int n,m,k;
int c[30]={};
int t=0;
int main() {
	cin>>n>>m;
	rep(i,0,n){
		cin>>k;
		rep(i,0,k){
			cin>>t;
			c[t-1]++;
		}
	}
	int ans=0;
	rep(i,0,m){
		ans+=c[i]/n;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast","-funroll-all-loops","-ffast-math")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define SZ(a) int(a.size())
#define ALL(x) (x).begin(),(x).end()
#define trav(a,x) for (auto& a: x)
#define LOG(FMT...) fprintf(stderr, FMT)
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int mod = 1e9+7;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base=2333, P_1=19260811, P_2=999998639;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int k;
int chk(int x){
    while(x){
        int kp = x % 10;
        if(kp == k)return true;
        x /= 10;
    }return false;
}
int main()
{
    int  a , b ;
    cin >> k >> a >> b;
    for(int i = a; i <= b;i++){
        if(i % k == 0){
            puts("OK");
            exit (0);
        }
    }
    puts("NG");
}

Measured memory_bytes: 3100
import java.util.*;
 
public class Main {
 
	public static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
    
	      long n = scan.nextLong();
	      StringBuilder s = new StringBuilder();
	      
	      while(n > 0) 
	      {
	    	char j = (char)(n % 26 + 96);
	    	if(n%26 == 0) {
	    		j = 122;
	    		n -= 26;
	    	}
	    	s.append(j);
	        n /= 26;
	      }
	      	
	      for(int i=s.length()-1; i>=0; i--) 
	      {
	    	  System.out.print(s.charAt(i));
	      }
      
    }
}

Measured memory_bytes: 35812
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  // val inputs = Seq("56 25 31")
  val nums = inputs.head.split(" ").map(_.toInt)
  val sum = Math.abs(nums(0) + nums(1))
  val dis = Math.abs(nums(0) - nums(1))

  println(if (sum == nums(2) || dis == nums(2)) { "Yes" } else { "No" })
}

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

int main(){
    int x;
    cin >> x;
    int y;
    cin >> y;
    while (x!=0 || y!=0) {
        if (x>=y) {
            cout << y << " " << x << endl;
        
        } else {
            cout << x << " " << y << endl;
           }
            cin >> x;
            cin >> y; 
    }
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#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)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
int flag[MAX_N];
vi G[MAX_N];

int main() {
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int x = 1;
    int ans[MAX_N] = {};
    int count = 0;
    while(true){
        flag[x] = 1;
        ans[count] = x;
        count++;
        int f = 0;
        rep(i,G[x].size()){
            if(flag[G[x][i]] == 0){
                x = G[x][i];
                f = 1;
                break;
            }
        }
        if(f==0){
            break;
        }
    }
    
    int ans2[MAX_N] = {};
    int count2 = 0;
    x = 1;
    while(true){
        flag[x] = 1;
        ans2[count2] = x;
        count2++; 
        int f = 0;
        rep(i,G[x].size()){
            if(flag[G[x][i]] == 0){
                x = G[x][i];
                f = 1;
                break;
            }
        }
        if(f==0){
            break;
        }
    }
    cout << count + count2 - 1 << endl;
    drep(i,count){
        cout << ans[i] << ' ';
    }
    srep(i,1,count2){
        cout << ans2[i] << ' ';
    }
    cout << endl;

    return 0;
}
 
 


Measured memory_bytes: 10624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    int tmp = 0;
    for(int i = 0; i < n; i++) {
        if(i + 1 != v[i]) {
            tmp++;
        }
    }
    
    if(tmp == 0 || tmp == 2) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    
    return 0;
}



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

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


Measured memory_bytes: 3624
import java.util.*;
import java.util.stream.*;
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in1 = br.readLine().split(" ");
    int N = Integer.parseInt(in1[0]);
    int M = Integer.parseInt(in1[1]);

    List<Integer>[] graph = new List[3 * N];
    for(int i = 0; i < 3 * N; i++) graph[i] = new ArrayList<Integer>();

    for(int i = 0; i < M; i++){
      in1 = br.readLine().split(" ");
      int u = Integer.parseInt(in1[0]);
      int v = Integer.parseInt(in1[1]);
      u--; v--;
      graph[3 * u].add(3 * v + 1);
      graph[3 * u + 1].add(3 * v + 2);
      graph[3 * u + 2].add(3 * v);
    }

    in1 = br.readLine().split(" ");
    int S = Integer.parseInt(in1[0]);
    int T = Integer.parseInt(in1[1]);
    S--;
    T--;
    S *= 3;
    T *= 3;

    br.close();

    int[] minPath = new int[3 * N];
    Arrays.fill(minPath, -1);
    minPath[S] = 0;

    Queue<Integer> que = new ArrayDeque<>();
    que.add(S);

    while(!que.isEmpty()){

      int edge = que.poll();

      for(int next : graph[edge]){
        if(minPath[next] != -1) continue;

        minPath[next] = minPath[edge] + 1;
        que.add(next);
      }
    }

    int ans = minPath[T];
    if(ans == -1 || ans % 3 != 0) System.out.println(-1);
    else System.out.println(ans / 3);
  }
}

Measured memory_bytes: 90320
n = int(input())
result = True
ws = set()
last = ""
for a in range(n):
    w = input()
    top = w[0]
    if (a > 0):
        if (last != top):
            result = False
            break
    ws.add(w)
    last = w[len(w) - 1]
    
if (len(ws) != n):
    result = False

if (result):
    print ("Yes")
else:
    print ("No")

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

#define mod 1e9+7
#define pb push_back

void add_self(int& here, int y){
	here += y;
	if(here >= mod)
		here -= mod;
	return;
}

void sub_self(int& here, int y){
	here -= y;
	if(here <= 0)
		here += mod;
	return;
}

int main(void){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0;i < n;i++)
		cin >> a[i];
	vector<int> dp(k+1, 0); // dp[i] - used candies
	dp[0] = 1;
	for(int i = 0;i < n;i++){ // n children
		vector<int> fake(k+1);
		for(int used = k;used >= 0;used--){
			int l = used+1;
			int r = used+min(k-used, a[i]);
			if(l <= r){
				add_self(fake[l], dp[used]);
				if(r < k){
					sub_self(fake[r+1], dp[used]);
				}
			}
		}
		int temp = 0;
		for(int x = 0;x <= k;x++){
			add_self(temp, fake[x]);
			add_self(dp[x], temp);
		}
	}
	cout << dp[k] << endl;
}


Measured memory_bytes: 1024
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n,x=map(int, input().split())
xn = list(map(int, input().split()))

num_list = [abs(x-xn[i]) for i in range(n)]

Ans = gcd_list(num_list)
print(Ans)

Measured memory_bytes: 20540
# -*- coding: utf-8 -*-
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, Q, *A = map(int, read().split())

    B = [0] * N
    for a in A:
        B[a - 1] += 1

    ans = [0] * N
    for i, b in enumerate(B):
        if Q >= K + b:
            ans[i] = 'No'
        else:
            ans[i] = 'Yes'

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


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

int main(){
  int n;
  string s,ans,temp;
  cin >> s;
  for(int i = 0; i < s.size(); i++)
  {
    if(s[i]=='B'){
      if(ans.size() != 0){
        temp = ans.substr(0,ans.size()-1);
        ans = temp;
      }
    }
    else{
      ans += s[i];
    }
  }
  cout << ans << endl; 

  return 0;
}


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

typedef long long ll;

int main(){
  int N,c = 0,f=0;
  cin >> N;
  for(int i=0; i<N; i++){
    int d1,d2;
    cin >> d1 >> d2;
    if(d1 == d2) c++;
    else c = 0;
    if(c >= 3) f =1;
  }
  if(f == 1) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    char c = 'a';
    boolean printed = false;
    boolean appear = false;
    
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < s.length(); j++) {
        if (s.charAt(j) == (c + i)) {
          appear = true;
          break;
        }
      }
      if (appear == false) {
        System.out.println((char) (c + i));
        printed = true;
        break;
      }
      appear = false;
    }

    if (printed == false) {
      System.out.println("None");
    }
  }
}

Measured memory_bytes: 25292
package main

import (
	"fmt"
	"sort"
)

type Int64 []int64

func (a Int64) Len() int           { return len(a) }
func (a Int64) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Int64) Less(i, j int) bool { return a[i] < a[j] }

func scanNums(len int) (nums []int64) {
	var num int64
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func main() {
	var n int
	var m int64
	
	fmt.Scan(&n)
	fmt.Scan(&m)
	x := make(map[int64]int64)
	for i := 0; i < n; i++ {
	    var a, b int64
	    fmt.Scan(&a)
		fmt.Scan(&b)
		x[a] += b
	}
	
	var keys Int64
	for k, _ := range x {
	    keys = append(keys, k)
	}
    sort.Sort(keys)

//  sort.Slice doesn't work on the version 1.6	
// 	sort.Slice(keys, func(i, j int) bool {
//         return keys[i] < keys[j]
//     })
	
	var c1, c2 int64 = 0, 0
	for _, k := range keys {
	    if x[k] + c1 < m {
	        c1 += x[k]
	        c2 += k * x[k]
	    } else {
	        c2 += k * (m - c1)
	        break
	    }
	}
    fmt.Println(c2)
}


Measured memory_bytes: 10240