akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e30
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, L, R, K, X,Y, A, B, C, Z;
ll ans;
string S;
ll a[200];
ll x[100000000];
ll y[100000000];
ll nowcost = 1;
ll twopow[202020];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll DP[1000001];
int main() {
	cin>>N>>K>>X>>Y;
	ans +=min(N,K)*X;
	ans += max(0ll,N-K)*Y;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e6 +1)
#define INFL LLONG_MAX
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

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

ll mult(ll a, ll b) {
	ll x = 0;
	while (b) {
		if (b & 1) x = (x + a);
		a = (a + a);
		b >>= 1;
	}
	return x;
}



int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;

	// Write your code here

	int t = 1;
	//cin >> t;
	while (t--) {
		ll n, k;
		cin >> n >> k;
		vl v(n);
		for (int i = 0; i < n; i++) {
			cin >> v[i];
		}
		sort(v.begin(), v.end());
		ll sum = 0;
		int i = 0;
		while (k--) {
			sum += v[i++];
		}
		cout << sum << "\n";
	}


	return 0;
}

Measured memory_bytes: 3620
n = int(input())
a = list(map(int,input().split()))

m = 1000
s = a[0]
kabu = 0
zankin = m
for i in range(1, n):
    if a[i] > s:
        kabu = m//s
        zankin = m%s
        m = a[i] * kabu + zankin
    s = a[i]
print(m)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (S.at(i) == T.at(i)) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n;
	cin>>n;
	long long ret = 0;
	int neg = 0;
	vector<long long>arr(n);
	for(int i=0; i<n; i++){
		cin>>arr[i];
		if(arr[i]<0) neg++;
		ret+=abs(arr[i]);
		arr[i] = abs(arr[i]);
	}
	if(neg%2) ret-=2*(*min_element(arr.begin(),arr.end()));
	cout<<ret;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    llint ans = 0;
    char rem = 0;
    REP(i, N){
        llint a;
        cin >> a;
        if(a == 0){
            rem = 0;
            continue;
        }
        ans += a / 2;
        if(a%2 == 1){
            if(rem == 1){
                ans++;
                rem = 0;
            }else{
                rem = 1;
            }
        }
    }

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

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    int[] C = new int[K];
    int[] D = new int[K];
    for (int i = 0; i < K; i++) {
      C[i] = sc.nextInt();
      D[i] = sc.nextInt();
    }
    sc.close();
    /*
    */

    @SuppressWarnings("unchecked")
    Set<Integer>[] g = new Set[N + 1];
    int[] fc = new int[N + 1];
    for (int i = 0; i < M; i++) {
      int a = A[i];
      int b = B[i];
      if (g[a] == null && g[b] == null) {
        Set<Integer> set = new HashSet<>();
        set.add(a);
        set.add(b);
        g[a] = set;
        g[b] = set;
      } else if (g[a] == null) {
        Set<Integer> set = g[b];
        set.add(a);
        g[a] = set;
      } else if (g[b] == null) {
        Set<Integer> set = g[a];
        set.add(b);
        g[b] = set;
      } else if (g[a] != g[b]) {
        Set<Integer> setL = g[a];
        Set<Integer> setS = g[b];
        if (setL.size() < setS.size()) {
          Set<Integer> temp = setL;
          setL = setS;
          setS = temp;
        }
        setL.addAll(setS);
        for (int c : setS) g[c] = setL;
      }
      fc[a]++;
      fc[b]++;
    }

    int[] bc = new int[N + 1];
    for (int i = 0; i < K; i++) {
      int c = C[i];
      int d = D[i];
      if (g[c] == g[d]) {
        bc[c]++;
        bc[d]++;
      }
    }
    /*
    sc.close();
    */

    int[] ans = new int[N + 1];
    for (int i = 1; i < N + 1; i++)
      if (g[i] != null)
        ans[i] = g[i].size() - 1 - fc[i] - bc[i];

//    StringBuilder buf = new StringBuilder();
    for (int i = 1; i < N + 1; i++)
      System.out.print(ans[i] + " ");
    System.out.println();
//      buf.append(ans[i]).append(' ');
//    System.out.println(buf);
  }
}

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

void generate_luca_num_ary(int n, vector<int64_t> &luca_ary) {
    if (n == 0) {
        luca_ary.at(n) = 2;
    } else if (n == 1) {
        luca_ary.at(n) = 1;
    } else {
        if (luca_ary.at(n - 2) == 0) {
            generate_luca_num_ary(n - 2, luca_ary);
        }
        if (luca_ary.at(n - 1) == 0) {
            generate_luca_num_ary(n - 1, luca_ary);
        }
        luca_ary.at(n) = luca_ary.at(n - 1) + luca_ary.at(n - 2);
    }
}

int main() {
    int n;
    cin >> n;
    vector<int64_t> luca_ary(n+1, 0);
    generate_luca_num_ary(n, luca_ary);
    cout << luca_ary.at(n);
}

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

vector<int> g(200010,0);

void dfs(vector<vector<int>> &G,vector<int> &s,int v,int n) {
  s[v] = 1;
  g[n]++;
  for(auto nv : G[v]) {
    if(!s[nv]) dfs(G,s,nv,n);
  }
  
}

int main() {

  int N,M;
  cin >> N >> M;

  vector<vector<int>> G(N,vector<int>(0));
  vector<int> seen(N);

  for(int i = 0;i < M;i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  int ans = 0,g_num = 0;
  for(int i = 0;i < N;i++) {
    if(!seen[i]) dfs(G,seen,i,g_num);
    g_num++;
  }

  sort(g.rbegin(),g.rend());
  cout << g[0] << endl;



}


Measured memory_bytes: 25164
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        Map<String, Integer> res = new HashMap<>();

        int maxCnt = 0;
        for(int i=0;i<N;i++){
            String s = sc.next();
            res.putIfAbsent(s, 0);
            res.put(s, res.get(s)+1);
            maxCnt = Math.max(res.get(s),maxCnt);
        }
        final int mx = maxCnt;
        res.entrySet().stream()
                .filter(ent->ent.getValue() == mx)
                .map(Map.Entry::getKey)
                .sorted()
                .forEach(System.out::println);

    }
}

Measured memory_bytes: 87364
import numpy as np
# 複数個格納
# A,B = map(int, input().split())
#A = int(input())
# 行列化
# A = np.array(A)
# A=A.reshape(1,-1)
# A=A.T
#行列の比較
#C=((A%2 == vector0).all())
#行列の作成
#A=(np.arange(0,2000,500)).reshape(1,-1)

N,A,B = map(int, input().split())
count=0
for i in range(1, N+1):
    i1=i%10
    i2=((i-i1)%100)/10
    i3=((i-i1-i2*10)%1000)/100
    i4=((i-i1-i2*10-i3*100)%10000)/1000
    i5=(i-i1-i2*10-i3*100-i4*1000)/10000

    
    if  A<= i1+i2+i3+i4+i5 <=B:
        count=count+i

print(count)



Measured memory_bytes: 12488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  int N;
  cin >> N;
  int x[N],y[N];
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i];
  }

  vector<int> a(N);
  for(int i = 0; i < N; i++){
    a[i] = i;
  }
  double sum = 0;
  do{
    for(int i = 0; i < N-1; i++){
      sum += pow(pow((x[a[i]]-x[a[i+1]]), 2) + pow((y[a[i]]-y[a[i+1]]), 2), 0.5);
    }
  }while(next_permutation(a.begin(),a.end()));

  int warukazu = 1;
  for(int i = 1; i <= N; i++){
    warukazu *= i;
  }

  double ans = sum / warukazu;
  cout << fixed << ans << setprecision(16) << endl;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;


int N, W[1010], S[1010], V[1010];
ll dp[1010][30101];
//---------------------------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, N) cin >> W[i] >> S[i] >> V[i];

    vector<int> ord(N);
    iota(all(ord), 0);
    sort(all(ord), [&](int a, int b) { return min(S[a], S[b] - W[a]) > min(S[b], S[a] - W[b]); });

    rep(i, N) {
        rep(tot, 20101) {
            int a = ord[i];
            chmax(dp[i + 1][tot], dp[i][tot]);
            if (tot <= S[a]) chmax(dp[i + 1][tot + W[a]], dp[i][tot] + V[a]);
        }
    }

    ll ans = 0;
    rep(tot, 20101) chmax(ans, dp[N][tot]);
    cout << ans << endl;
}

Measured memory_bytes: 234368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void print(T x){cout << x << endl;}
template<class T>void printvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
typedef pair<int, int> P;

int main()
{
    int N, W; cin >> N >> W;
    vector<P> item(N);
    rep(i, N){
        cin >> item[i].first >> item[i].second;
    }

    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    FOR(i, item[0].first, W+1) dp[0][i] = item[0].second;
    FOR(i, 1, N+1){
        FOR(j, 1, W+1){
            if(j - item[i].first>=0) chmax(dp[i][j], dp[i-1][j-item[i].first] + item[i].second);
            chmax(dp[i][j], dp[i-1][j]); 
        }
    }
    print(dp[N][W]);
    return 0;
}

Measured memory_bytes: 80256
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;


int h, w, n;
int x, y;
string a, b;
int l, r, ll, rr, u, d, uu, dd;
int fx, fy;

inline void yes() {
    cout << "NO\n";
    exit(0);
}

inline bool solve(char c1, char c2, char c3, char c4) {
    int x = fx;
    int y = fy;
    for (int i = 0; i < n; ++i) {
        if (a[i] == c1) {
            if (c1 == 'L') --y;
            else ++y;
        } else if (a[i] == c2) {
            if (c2 == 'U') --x;
            else ++x;
        }
        if (x < 1 || x > h || y < 1 || y > w) return false;
        if (b[i] == c3) {
            if (c3 == 'L') --y;
            else ++y;
        } else if (b[i] == c4) {
            if (c4 == 'U') --x;
            else ++x;
        }
        x = max(1, x);
        x = min(x, h);
        y = max(y, 1);
        y = min(y, w);
    }
    return true;
}

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> h >> w >> n;
    cin >> fx >> fy;
    cin >> a >> b;
    string s1 = "LR";
    string s2 = "UD";
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            int x = (i + 1) % 2;
            int y = (j + 1) % 2;
            if (!solve(s1[i] ,s2[j], s1[x], s2[y])) yes();
        }
    }
    cout << "YES\n";
    return 0;
}



Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,P;
    cin >> A >> P;
    print((P + A*3) / 2);
    
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#define MAXN (1 << 21)
int g[101][101], d[101], n;
bool vis[101];

int mst()
{
  int sum = 0;
  d[0] = 0;
  for (int j = 0; j < n; j++)
  {
    int u = -1;
    int mini = MAXN;
    for (int i = 0; i < n; i++) // take node from V-T to T
    {
      if (d[i] < mini && !vis[i])
      {
        u = i;
        mini = d[i];
      }
    }
    if (u == -1) return -1;
    sum += mini;
    vis[u] = true;
    for (int v = 0; v < n; v++) // update smallest weight
    {
      if (!vis[v] && g[u][v] >= 0 && d[v] > g[u][v])
      {
        d[v] = g[u][v];
      }
    }
  }
  return sum;
}

int main()
{
  memset(vis, false, sizeof(vis));
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    d[i] = MAXN;
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      scanf("%d", &g[i][j]);
    }
  }
  printf("%d\n", mst());
}



Measured memory_bytes: 2684
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
const int mod=998244353;
const int maxn1=1e5+10;
typedef long long ll;
ll a[maxn1];
ll abc(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)
			res=(res*a+mod)%mod;
		a=(a*a+mod)%mod;
		b>>=1;
	}
	return res;
}
int main()
{
	ll n;
	ll x;
	ll ant=-1;
	bool flag=0;
	ll ans=1;
	scanf("%lld",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&x);
		if(i==0&&x!=0||i!=0&&x==0)
			flag=1;
		
		a[x]++;
		if(x>ant)
			ant=x;
	}
	if(flag==1)
		printf("0\n");
	else
	{
		for(int i=2;i<=ant;i++)
		{
			if(a[i]==0)
			{
				flag=1;
				break;
			}
			ans=(ans*abc(a[i-1],a[i])+mod)%mod;
//			printf("%lld\n",ans);
		}
		if(flag)
			printf("0\n");
		else
			printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.lang.Math;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        double x1 = input.nextDouble();
        double x2 = input.nextDouble();
        double y1 = input.nextDouble();
        double y2 = input.nextDouble();
        double dis = Math.hypot((y1 - x1), (y2 - x2));
        System.out.println(dis);
        
    }
}


Measured memory_bytes: 28136
# 二分探索
from bisect import bisect_left, bisect_right

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

for x in [A, B, C]:
    x.sort()

result = 0
for b in B:
    a = bisect_left(A, b)
    c = N - bisect_right(C, b)
    result += a * c
print(result)


Measured memory_bytes: 22720
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, W;
    cin >> n >> W;
    vector<long long> w(n + 1), v(n + 1);
    for (int i = 1; i <= n; i++) cin >> w[i] >> v[i];
    long long dp[n + 1][W + 1];
    for (int i = 0; i <= n; i++) for (int j = 0; j<= W; j++) dp[i][j] = 0;
    // dp[i] la gia tri lon nhat tai i voi trong luong j
    //dp[0][w[0]] = v[0];
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= W; j++){
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if (j - w[i] >= 0){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }

        }
    }

    cout << dp[n][W];
}


Measured memory_bytes: 79104
def solve(string):

    n, *txy = map(int, string.split())
    checks = [
        abs(x) + abs(y) <= t and (t + x + y) % 2 == 0
        for t, x, y in zip(txy[::3], txy[1::3], txy[2::3])
    ]
    return "Yes" if all(checks) else "No"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 28224
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using ii = pair<int, int>;

#define eb emplace_back

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

  unordered_set<string> s;
  int n;
  cin >> n;
  while (n--) {
    string x;
    cin >> x;
    s.emplace(x);
  }

  cout << s.size();
}


Measured memory_bytes: 13832
#include <iostream>
#include <cctype>
#include <string>
#include <string.h>
using namespace std;
int main(){
    string s;
    while(true){
        
    int a='0',b='0',c='0',d='0',sum = 0;
        cin >> s;
        if(s != "0"){
            for(int i = 0; i < s.length(); i ++){
                sum += s[i] - '0';
            }
            cout << sum << endl;
        } else {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 1e6+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n,m;
    cin>>n>>m;
    char vec[n+2][m+2];
    for(int i=0;i<=n+1;i++){
        if(i==0||i==n+1){
            for(int j=0;j<=m+1;j++){
                vec[i][j]='#';
            }
        }
        else {
            vec[i][0]=vec[i][m+1]='#';
            for(int j=1;j<=m;j++){
                char c;
                cin>>c;
                vec[i][j]=c;
            }
        }
    }
    for(int i=0;i<=n+1;i++){
        for(int j=0;j<=m+1;j++){
            cout<<vec[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    while(t--){
       string s; cin >> s;
       int ans = 0;
       for(auto i : s){
          ans += (i - '0');
          ans %= 9;
       }
       cout << ((!ans) ? "Yes" : "No") << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N, A, B;
  cin >> N >> A >> B;

  ll M = A+B;

  ll ret = A * (N/M);

  ret += min(A, N%M);
  
  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let x: u64 = read();
    if x % 11 == 0 {
        println!("{}", (x / 11) * 2);
    } else {
        let mut ans = (x / 11) * 2;
        if x % 11 > 6 {
            ans += 2;
        } else {
            ans += 1;
        }
        println!("{}", ans)
    }
}


Measured memory_bytes: 2136
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


def solve(n):
    return n


if __name__ == "__main__":
    s, w = inums()
    print("safe" if s > w else "unsafe")


Measured memory_bytes: 9156
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,m,yu=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>m;
		if(m%2==1)
		{
			yu=1;
		}
	 } 
	 if(yu==1)
	 {
	 	printf("first");
	 }
	 else
	 {
	 	printf("second");
	 }
	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ni()
A = na()
d = {}
for i in range(N):
    if A[i] not in d.keys():
        d[A[i]] = 0
    else:
        d[A[i]] += 1
s = 0
for k, v in d.items():
    s += v
if s % 2 == 0:
    print(len(d))
else:
    print(len(d) - 1)

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

using namespace std;

typedef long long LL;

#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define LEN(a) int((a).size())
#define SORT(a) sort((a).begin(), (a).end())
#define CLR(a) memset((a), 0, sizeof(a))

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
    int n, k;
    cin >> n >> k;
    vector<LL> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    LL ans = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k - i; j++) {
            if (i == 0 && j == 0) continue;
            if (i + j > n) continue;
            vector<LL> t;
            for (int l = 0; l < i; l++) {
                t.PB(v[l]);
            }
            for (int l = n - 1; l > n - 1 - j; l--) {
                t.PB(v[l]);
            }
            SORT(t);
            int left = k - i - j;
            LL sum = 0;
            for (int l = 0; l < LEN(t); l++) {
                if (t[l] < 0 && left > 0) left--;
                else sum += t[l];
            }
            ans = max(ans, sum);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	int d[n]; rep(i,n) cin >> d[i];
	int ans = 0;
	rep(i,n)rep(j,n){
		if(i>=j) continue;
		ans+=d[i]*d[j];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 234567;
const LL MOD = (LL)1e9 + 7;
LL pw2[MAXN];

LL gcd(LL a, LL b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

int main() {
    pw2[0] = 1;
    for (int i = 1; i < MAXN; i++)
        pw2[i] = (pw2[i - 1] * 2) % MOD;
    int N;
    scanf("%d", &N);
    map<pll, LL> mp;
    LL a0b0 = 0, a0 = 0, b0 = 0;
    for (int i = 0; i < N; i++) {
        LL a, b;
        scanf("%lld %lld", &a, &b);
        if (a == 0 && b == 0) a0b0++;
        else if (a == 0) a0++;
        else if (b == 0) b0++;
        else {
            LL coef = 1;
            if ((a < 0 && b > 0) || (a > 0 && b < 0))
                coef = -1;
            a = abs(a), b = abs(b);
            assert(a > 0);
            assert(b > 0);
            LL g = gcd(a, b);
            a /= g, b /= g;
            pll tmp = make_pair(coef * a, b);
            mp[tmp]++;
        }
    }
    LL ans = 1;
    set<pll> used;
    for (auto it : mp) {
        pll p = it.first;
        LL a = p.first, b = p.second;
        LL x = it.second;
        if (used.count(p)) continue;
        pll rv = make_pair(-b, a);
        if (a < 0) {
            rv.first *= -1;
            rv.second *= -1;
        }
        assert(rv.second > 0);
        if (mp.count(rv)) {
            LL y = mp[rv];
            LL tmp = (pw2[x] + pw2[y] - 1) % MOD;
            used.insert(rv);
            ans = (ans * tmp) % MOD;
        } else {
            ans = (ans * pw2[x]) % MOD;
        }
    }
    ans = mul(ans, (pw2[a0] + pw2[b0] - 1) % MOD) % MOD;
    printf("%lld\n", (ans + a0b0 -1 + MOD) % MOD);
    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
by Benq;
*/


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

char msg[10];
map<string, int> val;
int main(){
    int n;
    scanf("%d",&n);
    val["Male"] = 1;
    val["Female"] = 2;
    val["Vacant"] = 0;
    printf("0\n"); fflush(stdout);
    scanf("%s", msg);
    if(!val[msg]){
        return 0;
    }
    int status = val[msg]%2;
    int ss = 1, ee = n-1;
    while(ss <= ee){
        int mid = (ss + ee) >> 1;
        printf("%d\n", mid); fflush(stdout);
        scanf("%s", msg);
        if(!val[msg]){
            return 0;
        }
        if((mid + status) % 2 == val[msg] % 2){
            ss = mid + 1;
        }else{
            ee = mid - 1;
        }
    }
}


Measured memory_bytes: 852
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true){
			int H=sc.nextInt();
			int W=sc.nextInt();
			
			if(H==0&&W==0) {
				break;
			}
			//最初の描画
			for(int i=0; i<W; i++) {
				System.out.printf("#");
			}
			System.out.printf("%n");
			
			//真ん中の描画
			for(int i=0; i<H-2; i++) {
				System.out.printf("#");
				
				for(int j=0; j<W-2; j++) {
					System.out.printf(".");
				}
				System.out.printf("#%n");
			}
			
			//最後の描画
			for(int i=0; i<W; i++) {
				System.out.printf("#");
			}
			System.out.printf("%n%n");
		}
	}

}



Measured memory_bytes: 68076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.begin(), c.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
#define Sort(a) sort(Range(a));
#define DeSort(a) sort(RevRange(a));

using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    Cin(int, k);
    Cin(int, x);
    Cin(int, y);
    Cout((n <= k) ? n*x : k*x + (n-k)*y);
    //Cout(() ? "Yes" : "No");
    //Cout(() ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <array>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <utility>
#include <tuple>
#include <algorithm>
#include <limits>
#include <fstream>
#include <numeric>

namespace
{
	template<int N>
	std::array<int, N> GetValue(std::istream& stream)
	{
		std::string buf;
		std::getline(stream, buf);

		std::stringstream sstr(buf);
		std::array<int, N> retval;

		for (int i = 0; i < N; ++i)
		{
			std::getline(sstr, buf, ' ');
			retval[i] = std::stoi(buf);
		}

		return retval;
	}

	std::vector<int> GetValue(std::istream& stream, int num, char delim)
	{
		std::string buf;
		std::vector<int> retval;
		retval.reserve(num);

		for (int i = 0; i < num; ++i)
		{
			std::getline(stream, buf, delim);
			retval.push_back(std::stoi(buf));
		}

		return retval;
	}

	void Print(const std::vector<int>& values)
	{
		std::cout << values[0];

		auto f = [](int e) {std::cout << ' ' << e; };

		std::for_each(values.begin() + 1, values.end(), f);

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

int main(int argc, char* argv[])
{
	//auto file = (argc == 1) ? std::ifstream() : std::ifstream(argv[1]);
	//std::istream& stream = (argc == 1) ? std::cin : file;
	std::istream& stream = std::cin;

	auto num = GetValue<1>(stream);

	std::vector<int> values = GetValue(stream, num[0], ' ');

	Print(values);

	for (int i = 1; i < num[0]; ++i)
	{
		int v = values[i];
		int j = i - 1;

		while (0 <= j && v < values[j])
		{
			values[j + 1] = values[j];
			--j;
		}

		values[j + 1] = v;

		Print(values);
	}
}



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

int main() {
  int s, s1, s2, s3;
  cin >> s;
  s1 = s/100;
  s2 = (s-s1*100)/10;
  s3 = (s-s1*100-s2*10)/1;
  cout << s1+s2+s3 << endl;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())
out = make_divisors(n)
ans = []
for i in out:
    if i == 1:
        continue
    m = n
    while m % i == 0:
        m //= i
    if m == 1 or m % i == 1:
        ans.append(i)
ans += make_divisors(n - 1)
# print(set(out))
print(len(set(ans)) - 1)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=200000+6;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    //    freopen ("INPUT.txt" , "r" , stdin);
    //    freopen ("OUTPUT.txt", "w" , stdout);
    // #endif
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    if ( a>w/2||b>h/2)
        cout<<-1<<'\n';
    else
    {
        int arr[h];
        memset( arr,0,sizeof ( arr));
        for ( int i=0;i<b;i++)
            arr[i]=1;
        int brr[h][w];
        memset( brr,0,sizeof ( brr));
        for ( int i=0;i<h;i++)
        {
            for ( int j=0;j<w;j++)
            {
                if ( j<a)
                    brr[i][j]=1;
            }
        }
        for ( int i=0;i<h;i++)
        {
            for ( int j=0;j<w;j++)
            {
                if ( arr[i]==0)
                {
                    if ( brr[i][j]==0)
                        cout<<1;
                    else
                        cout<<0;
                }
                else
                    cout<<brr[i][j];
            }
            cout<<'\n';
        }
    }
}

Measured memory_bytes: 5120
n = int(input())
a = list(map(int, input().split()))
inf = 10**16

def func(b):
    return sum([abs(a[i]-(b+i+1)) for i in range(n)])

# 3分探索を行う
low = -inf
high = inf

while abs(high-low) > 0.01:
    c1 = (low*2 + high)/3
    c2 = (low + high*2)/3

    if func(c1) > func(c2):
        low = c1
    else:
        high = c2
mid = (high+low)/2
ans = min(func(int(mid)), func(int(mid+1)), func(int(mid-1)))
print(ans)


Measured memory_bytes: 181756
#include <bits/stdc++.h>
#define LL long long
#define maxn 200005
using namespace std;
LL a[200005];
LL fa[2005];
int main()
{
    LL n,x,y;
    cin>>n>>x>>y;
    int ans[n+1];
    memset(ans,0,sizeof(ans));
    for(LL i=n;i>=2;i--)
      for(LL j=n-1;j>=1;j--)
      {
          LL tmp=min(i-j,abs(i-y)+1+abs(j-x));
          ans[tmp]++;
      }
    for(int i=1;i<=n-1;i++)
    {
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 256
s=input()
char=list(s)
if char[0]==char[1]:
  if char[2]==char[3] and char[0]!=char[2]:
    print('Yes')
  else:
    print('No')
elif char[0]==char[2]:
  if char[1]==char[3] and char[0]!=char[1]:
    print('Yes')
  else:
    print('No')
elif char[0]==char[3]:
  if char[1]==char[2] and char[0]!=char[1]:
    print('Yes')
  else:
    print('No')
else:
  print('No')

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

using namespace std;
typedef long long ll;

int main(){
  ll a; cin >> a;
  ll b; cin >> b;
  if(a == b){
    cout << 1 << "\n"; return 0;
  }
  //drop the LCP
  int k = -1;
  for(int i = 60; i >= 0; i--){
    if((a & (1LL<<i)) == (b & (1LL<<i))){
      continue;
    }
    else{
      k = i;
      break;
    }
  }
  a = a % (1LL<<k+1);
  b = b % (1LL<<k+1);
  ll c = b - (1LL<<k);
  int r = -1;
  for(int i=0;i<60;i++){
    if((1LL<<i)-1 >= c){
      r = i;
      break;
    }
  }
  ll g = (1LL<<r) - 1;
  if(g < a){
    cout << 2 * ((1LL<<k) - a) + (1LL<<r) << "\n";
  }
  else{
    //you can get everything from a to 1LL<<k, exclusive on the right.
    cout << (1LL<<k+1) - a << "\n";
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	long long a, b;
	cin >> a >> b;
	if (a == 1)
		a = 3;
	if (b == 1)
		b = 3;
	cout << (a - 2)*(b - 2) << "\n";
	return 0;
}

Measured memory_bytes: 256
s = input()
if 'N' in s and 'S' not in s:
    print('No')
    exit()
elif 'S' in s and 'N' not in s:
    print('No')
    exit()
elif 'W' in s and 'E' not in s:
    print('No')
    exit()
elif 'E' in s and 'W' not in s:
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
    
using namespace std;
using ll = long long;
using pii = pair<int, int>;
    
const int oo = 1e9 + 7;
const int mod = 1e9 + 7, maxn = 200200;
const double PI = acos(-1);
vector<int> sz(maxn, 1), p(maxn), ans(maxn, 0);

void init(){
    for (int i=1; i<maxn; i++){
        p[i] = i;
    }
}

int find(int v){
    if (p[v] == v) return v;
    return p[v] = find(p[v]);
}

void union_set(int a, int b){
    a = find(a);
    b = find(b);
    if (a != b){
        if (sz[a] < sz[b]) swap(a, b);
        p[b] = a;
        sz[a] += sz[b];
    }
}
int main(){
    string s;
    list<char> ans;
    bool inv = false;
    int q, t, f, n;
    char c;
    cin >> s;
    cin >> q;
    n = s.size();

    for (int i=0; i<n; i++){
        ans.push_back(s[i]);
    }

    for (int i=0; i<q; i++){
        cin >> t;
        if (t == 1){
            inv = (inv^1);
        }
        else {
            cin >> f >> c;
            if ((!inv and f == 1) || (inv and f == 2)){
                ans.push_front(c);
            }
            else {
                ans.push_back(c);
            }
        }
    }

    string res;

    for (auto it: ans) res.push_back(it);
    if (inv) reverse(all(res));

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 15704
#include<stdio.h>
using namespace std;

int main() {
	int a,b,c,d=0;
	scanf("%d %d %d", &a, &b, &c);
	for (int i = a; i <= b; i++)
	{
		if (c%i == 0)
		{
			d++;
		}
	}
	printf("%d\n", d);
}


Measured memory_bytes: 2748
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

int Debug = 1;

string str;

string Interaction(vector<int> vec) {
	if (Debug == 1) {
		cout << "?";
		for (int i = 0; i < vec.size(); i++) cout << " " << vec[i];
		cout << endl;

		string ret; cin >> ret;
		return ret;
	}
	if (Debug == 2) {
		int v1 = 0, v2 = 0;
		for (int i = 0; i < vec.size(); i++) {
			if (str[vec[i] - 1] == 'R') v1++;
			else v2++;
		}
		if (v1 > v2) return "Red";
		return "Blue";
	}
}

void destroy() {
	for (int i = 0; i < 1000000000; i++) cout << i << endl;
}

string getranged(int cl, int cr) {
	vector<int> vec;
	for (int i = cl; i <= cr; i++) vec.push_back(i);
	return Interaction(vec);
}

string solve(int N) {
	// 変曲点を探す
	string A1 = getranged(1, N); int critical = 0;
	for (int i = 7; i >= 0; i--) {
		int I = min(N + 1, critical + (1 << i));
		string A2 = getranged(I, I + N - 1);
		if (A1 == A2) { critical += (1 << i); }
	}

	// 変曲点から各ボールの色を求める
	vector<int> vec1, vec2;
	for (int i = 1; i <= 2 * N; i++) {
		if (critical + 1 <= i && i <= critical + N - 1) vec1.push_back(i);
		else if (i != critical && i != critical + N) vec2.push_back(i);
	}
	
	string ans = "";
	for (int i = 1; i <= 2 * N; i++) {
		if (critical + 1 <= i && i <= critical + N - 1) {
			vector<int> E = vec2; E.push_back(i);
			string V = Interaction(E); assert(V != "-1");
			if (V == "Blue") ans += "B";
			else ans += "R";
		}
		else {
			vector<int> E = vec1; E.push_back(i);
			string V = Interaction(E); assert(V != "-1");
			if (V == "Blue") ans += "B";
			else ans += "R";
		}
	}
	return ans;
}

int main() {
	int N;
	if (Debug == 1) cin >> N;
	if (Debug == 2) cin >> N >> str;

	string P = solve(N);
	cout << "! " << P << endl;
	return 0;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> p;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n;
    cin >> n;
    std::vector<int> out;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        out.pb(temp);
    }
    std::sort(all(out), std::greater<int>());
    int flag = 0;
    int fs[2];
    for (int i = 0; i + 1 < out.size(); i++) {
        if (out[i] == out[i + 1]) {
            if (flag == 0) {
                fs[0] = out[i];
                flag++;
                i++;
            } else {
                fs[1] = out[i];
                flag++;
                break;
            }
        }
    }
    if (flag < 2) {
        cout << 0 << endl;
    } else {
        cout << fs[0] * fs[1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

int main(void) {
    int a, b, k, c;
    scanf("%d %d %d", &a, &b, &k);
    vector<int> kth;
     
    c=a;
    if(a>b)c=b;
    int count = 0;
    for(int i=1;i<=c;i++) {
        if(a%i==0&&b%i==0) {
            count ++;
            kth.push_back(i);
        }
    }

    sort(kth.begin(), kth.end(), std::greater<int>());

    printf("%d\n", kth[k-1]);


    return 0;
    }


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

int main() {
    int n , k , x , y;
    cin >> n;
    cin >> k;
    cin >> x;
    cin >> y;
    if(n <= k){
        cout << x * n << endl;
    }
    else{
        cout << x * k + y * (n - k) << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#pragma warning(disable:4996)
using namespace std;

int main(){
	string s1,s2;
	int n, cnt = 0;

	cin >> s1;
	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> s2;
		s2 += s2;
		for (int j = 0; j < s2.size() / 2; j++){
			if (s2.find(s1) != string::npos){
				cnt++;
				break;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int rate = Convert.ToInt32(Console.ReadLine());
            int targetRate = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine(targetRate * 2 - rate);
        }
    }
}


Measured memory_bytes: 11220
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int[] count = new int[3];
        for (int i = 0; i < n; i++) {
            int p = scanner.nextInt();
            if (p <= a) {
                count[0]++;
            } else if (p <= b) {
                count[1]++;
            } else {
                count[2]++;
            }
        }
        System.out.println(Math.min(Math.min(count[0], count[1]), count[2]));
    }
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
        string s;
        cin>>s;
        if(s!="AAA" && s!="BBB")
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        cout<<"No"<<endl;
        return 0;
}


Measured memory_bytes: 256
n = int(input())
L = []
for i in range(n):
    a,b = map(int,input().split())
    L.append((a,b))
L.sort()

max_zyun = L[0][0]
min_score = L[-1][1]

cnt = n + max_zyun-1 + min_score

for i in range(n-1):
    cnt +=(min(L[i+1][0] - L[i][0] -1,L[i][1] - L[i+1][1]-1))

print(cnt)

Measured memory_bytes: 22824
#include <stdio.h>
#include <string.h>

static char first[3004];
static char second[3004];
static int dyn[3004][3004];
static int dayn[3004][3004];
static int maxF, maxS;

int len(int i, int u) {
	if (i >= maxF || u >= maxS)
		return 0;
	if (dyn[i][u] != -1)
		return dyn[i][u];
	int x = 1;
	int a = len(i + 1, u);
	int b = len(i, u + 1);
	if (a < b) {
		x = 2;
		a = b;
	}
	if (first[i] == second[u]) {
		int c = len(i + 1, u + 1) + 1;
		if (a < c) {
			x = 3;
			a = c;
		}
	}
	dayn[i][u] = x;
	dyn[i][u] = a;
	return a;
}

void printLCS() {
	len(0, 0);
	int a = 0;
	int b = 0;
	while (dayn[a][b]) {
		if (dayn[a][b] == 1)
			a++;
		else if (dayn[a][b] == 2)
			b++;
		else {
			printf("%c", first[a]);
			a++;
			b++;
		}
	}
}

int main()
{
	scanf("%s", first);
	scanf("%s", second);
	maxF = strlen(first);
	maxS = strlen(second);
	for (int i = 0; i < maxF; i++)
		for (int u = 0; u < maxS; u++)
			dyn[i][u] = -1;
	printLCS();
}

Measured memory_bytes: 71040