akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,q;
    string s;
    cin>>n>>s>>q;
    map<char,set<int>> m;
    REP(i,'a','z')m[i]=set<int>();
    rep(i,s.length())m[s[i]].insert(i+1);
    while(q--){
        int a;
        cin>>a;
        if(a==1){
            int b;
            char c;
            cin>>b>>c;
            b--;
            m[s[b]].erase(b+1);
            m[c].insert(b+1);
            s[b]=c;
        }
        else{
            int l,r;
            cin>>l>>r;
            int ans=0;
            REP(i,'a','z'){
                int t=*m[i].lower_bound(l);
                ans+=l<=t&&t<=r;
            }
            cout<<ans<<endl;
        }
    }
}

Measured memory_bytes: 27172
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 
////////////////////////////////////////////////////////////////////////////////


int main(){
   
   int n,l;
   cin >> n >> l;
   
   vector<string> a(n);
   
   for(int i =0;i<n;i++) cin >> a[i];
   
   sort(all(a));
   
   for(int i =0;i<n;i++)cout <<a[i];
        
   
     
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int a[]=new int[n];
        for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
        long ans=0;

		int sz=100005;
		long fr[]=new long[sz];
		long inv[]=new long[sz];
		
		fr[0]=inv[0] = 1;
		fr[1]=inv[1] = 1;
		int mod=1000000007;
		
		for (int i = 2; i <sz; ++i){
		    inv[i] = inv[mod % i] * (mod - mod / i) % mod ;
		}
		
		for (int i = 2; i <sz; ++i){
		    fr[i]=fr[i-1]*i %mod;
		}

		long b[]=new long[sz];
		long s[]=new long[n+1];
		b[1]=inv[1];
		for (int i = 2; i < sz; i++) {
			b[i] = inv[i] + b[i-1];
			b[i] %= mod;
		}

		for (int i = 1; i <= n; i++) {
			s[i] = b[n-i+1] + b[i] - b[1];
			s[i] %= mod;
		}


		long x=0;
		for (int i = 1; i <= n; i++) {
			x=s[i]*a[i-1];
			x%=mod;
			x*=fr[n];
			x%=mod;
			ans+=x;
			ans%=mod;
		}

		
        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  

    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 42036
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,unsigned long long> pil;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,mx[N],dep[N],d[N];
queue<int> q;

struct node{int to,nxt;}sq[N<<1];
int all=0,head[N];
void addedge(int u,int v)
{
    all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;d[u]++;
}

int bfs(int p1,int p2)
{
    rep(i,1,n) mx[i]=dep[i]=0;
    q.push(p1);dep[p1]=1;
    if (p2) {q.push(p2);dep[p2]=1;}
    int ans=1;
    while (!q.empty())
    {
        int u=q.front();q.pop();
        mx[dep[u]]=max(mx[dep[u]],d[u]);
        ans=max(ans,dep[u]);
        go(u,i)
        {
            if (!dep[v]) 
            {
                dep[v]=dep[u]+1;q.push(v);
            }
        }
    }
    return ans;
}

pil solve(int p1,int p2)
{
    pil ans=mkp(bfs(p1,p2),mx[1]);
    if (p2) ans.sec--;
    rep(i,2,n)
    {
        if (mx[i]==1) break;
        else ans.sec*=(mx[i]-1);
    }
    if (p2) ans.sec*=2;
    return ans;
}

int main()
{
    n=read();
    rep(i,1,n-1) 
    {
        int u=read(),v=read();
        addedge(u,v);addedge(v,u);
    }
    if (n==2) {puts("1 2");return 0;}
    pil ans;ans.fir=n;ans.sec=1;
    rep(u,1,n)
    {
        ans=min(ans,solve(u,0));
        go(u,i)
        {
            ans=min(ans,solve(u,v));
        }
    }
    printf("%d %llu",ans.fir,ans.sec);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const std::vector<std::pair<int, int>> DXDY = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
constexpr char BR = '\n';

#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class S, class T> inline void chmax(S &a, T b){if(a < b) a = b;}
template <class S, class T> inline void chmin(S &a, T b){if(a > b) a = b;}
template <class T> inline void reverseSORT(Vec<T> &Array){
  std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline void putsDouble(double d){printf("%.16lf\n", d);}
inline int toInt(const string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res;
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~






int main(void){
    int n; scanf("%d", &n);
    printf("%d\n", 180 * (n-2));
    return 0;
}

Measured memory_bytes: 888
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <iostream>
#include<bits/stdc++.h>
using namespace std;

const int N=1e5+1 ; 
long long Dp[100][N],n,allowed;
pair<int,int>w[N];
long long calc(int idx ,int weight ){
        if(idx==n)return 0 ; 
        long long &ret = Dp[idx][weight];
        if(ret!=-1)return ret ; 
        ret = -1e9 ; 
        if(w[idx].first+weight<=allowed)ret = max(ret, w[idx].second+calc(idx+1,weight+w[idx].first));
        ret =max(ret,calc(idx+1,weight));
        return ret ; 
}
int main()
{ 
    cin>>n>>allowed;
    
    for(int i =0;i<n;i++){
            int a , b ; 
            
            cin>>a>>b ;
            w[i].first=a;
            w[i].second=b ;
            
    }
    memset(Dp,-1,sizeof Dp);
    cout<< calc(0,0);
}


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

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

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int l = Integer.parseInt(in.next());
            int r = Integer.parseInt(in.next());
            int d = Integer.parseInt(in.next());
            int ans = 0;

            for (int i = l; i <= r; i++) {
                if (i % d == 0) ans++;
            }

            // 出力
            out.println(ans);

        }

    }
}



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

using namespace std;

const int N = 2e5 + 5;

int n, a[N];
long long m, dp[N];

struct Line {
    long long a, b;
    Line (long long a = 0, long long b = 0): a(a), b(b) {}
};

struct ConvexHullTrick {
    deque <Line> dq;
    bool bad (Line l1, Line l2, Line l3) {
        return (l2.a - l1.a) * (l3.b - l1.b) > (l2.b - l1.b) * (l3.a - l1.a);
    }

    void add (long long a, long long b) {
        Line l = Line(a, b);
        while (dq.size() >= 2 && bad(dq[dq.size() - 2], dq[dq.size() - 1], l)) dq.pop_back();
        dq.push_back(l);
    }

    long long query (int x) {
        if (dq.empty()) return (long long)1e18;
        while (dq.size() >= 2 && dq[0].a * x + dq[0].b > dq[1].a * x + dq[1].b) dq.pop_front();
        return dq[0].a * x + dq[0].b;
    }
} slope;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    //dp(i) = min(dp(j) + m + ai^2 + aj^2 - 2aiaj)
    for (int i = 1; i <= n; i++) cin >> a[i];
    memset(dp, 0x3f, sizeof(dp)); dp[1] = 0;
    slope.add(-2LL * a[1], dp[1] + m + 1LL * a[1] * a[1]);

    for (int i = 2; i <= n; i++) {
        dp[i] = slope.query(a[i]) + 1LL * a[i] * a[i];
        slope.add(-2LL * a[i], dp[i] + m + 1LL * a[i] * a[i]);
    }

    cout << dp[n];
    return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

	ll h, w, a, b, c, ans=10000000000;
	cin >> h >> w;

	for(int i=1; i<h; i++){
		a=w*i;
		ll bh=(h-i)/2;
		ll ch=h-(i+bh);
		b=w*bh;
		c=w*ch;
		ans=min(ans, max(max(a, b), c)-min(min(a, b), c));

		ll bw=w/2;
		ll cw=w-bw;
		b=(h-i)*bw;
		c=(h-i)*cw;
		ans=min(ans, max(max(a, b), c)-min(min(a, b), c));
	}
	for(int i=1; i<w; i++){
		a=h*i;
		ll bw=(w-i)/2;
		ll cw=w-(i+bw);
		b=h*bw;
		c=h*cw;
		ans=min(ans, max(max(a, b), c)-min(min(a, b), c));

		ll bh=h/2;
		ll ch=h-bh;
		b=(w-i)*bh;
		c=(w-i)*ch;
		ans=min(ans, max(max(a, b), c)-min(min(a, b), c));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define pr(x) cout<<x
#define prs cout<<" "
#define prn cout<<"\n"
#define sc(x) cin>>x
#define ll long long int
#define pb push_back
#define rep(i,a,b,c)  for(int i=a; i<b; i+=c)

int main()
{
    ios :: sync_with_stdio(false); cin.tie(0);
    int t=1;
    //cin >> t;
    for(int i9 = 1; i9 <= t; i9++)
    {
        int n;
        cin>>n;
        double dp[n+1][n+1];
        double a[n];
        for(int i=0; i<n; i++)   cin>>a[i];
        memset(dp, 0.0, sizeof(dp));
        dp[0][0] = 1.0;
        rep(i, 1, n+1, 1)
        {
            rep(j, 0, n+1, 1)
            {
                //cout<<a[i-1]<<endl;
                if(j==0)
                  dp[i][j] = double(1.0-a[i-1])*double(dp[i-1][j]);
                else
                 dp[i][j] = double((1.0-a[i-1])*dp[i-1][j])  + double(a[i-1])*double(dp[i-1][j-1]);
                 //cout<<dp[i][j]<<endl;
                
            }
        }
        
        double result = 0.0;
        rep(i, n/2+1, n+1, 1)
          result += dp[n][i];
        printf("%.10lf\n",result);
    }
}

Measured memory_bytes: 70656
n = int(input())
s = list(map(int, input().split()))
count = 0

def main():
    mergeSort(s, 0, n)
    print(' '.join(map(str, s)))
    print(count)

def mergeSort(a, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        merge(a, left, mid, right)

def merge(a, left, mid, right):
    global count
    l = a[left:mid]
    r = a[mid:right]
    i = 0
    j = 0
    l.append(float('inf'))
    r.append(float('inf'))
    for k in range(left, right, 1):
        if l[i] < r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        count += 1


if __name__ == '__main__':
    main()



Measured memory_bytes: 66776
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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 int A = 0, C = 1, G = 2, T = 3;
bool agc_judge(int a, int b, int c, int now){
    vector<int> num = {c,b,a,now};
    rep(i, 4){
      if(i<3)swap(num[i], num[i+1]);
      if(num[0]==A && num[1] == G && num[2] == C) return false;
      if(num[1]==A && num[2] == G && num[3] == C) return false;
      if(i<3)swap(num[i], num[i+1]);
    }
    return true;
}

int dp[101][4][4][4];

int main(){ 
  int n; cin >> n;
  rep(i, 101)rep(a, 4)rep(b,4)rep(c,4)dp[i][a][b][c] = 0;
  rep(a, 4)rep(b, 4)rep(c, 4){
    if(a==C && b==G && c==A)continue;
    if(a==G && b==C && c==A)continue;
    if(a==C && b==A && c==G)continue;
    dp[3][a][b][c] = 1;
  }
  rept(i, 3, n){
    rep(a, 4){
      rep(b, 4){
        rep(c, 4){
          rep(j, 4){
            bool ok = agc_judge(a,b,c,j);
            if(ok)dp[i+1][j][a][b] = 
             (dp[i+1][j][a][b] + dp[i][a][b][c]) % MOD;
          }
        }
      }
    }
  }
  ll res = 0;
  rep(a, 4)rep(b,4)rep(c,4) res = (res + dp[n][a][b][c]) % MOD;
  cout << res << ln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if (L>R) {
    cout << "Left" << endl;
  }
  else if (L<R) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int INF = 1e9;
double temp_start = 500.0;
double temp_end = 0.001; 
int climb_loop = 10000000;
double temp;

int main(){
  int seed = 12345;
  mt19937 eng(seed);
  uniform_real_distribution<> uniform_01;

  // input
  int D;
  cin >> D;
  int c[26];
  rep(i,26) cin >> c[i];
  int s[D+1][26];
  rep(i,D) rep(j,26) cin >> s[i+1][j];
  
  // define parameter
  int last[D+1][26];
  int t[D+1];
  rep(i,D+1) rep(j,26) last[i][j] = 0;
  
  // calculate initial content climbing
  int content = 0;
  for(int day = 1; day <= D; day++) {
    int content_after = -INF;
    int best_kind = 0;
    rep(kind,26) {
      int res = content + s[day][kind];
      rep(j,26) {
        if(j == kind) last[day][j] = day;
        else last[day][j] = last[day-1][j];
        res -= c[j] * (day - last[day][j]);
      }
      if(res > content_after) {
        best_kind = kind;
        content_after = res;
      }
    }
    t[day] = best_kind;
    content = content_after;
    rep(j,26) {
      if(j == t[day]) last[day][j] = day;
      else last[day][j] = last[day-1][j];
    }
  }
   
  // simulated annealing
  rep(x,climb_loop) {
    int d = (eng() % D) + 1;
    int q = eng() % 26;
    if(q != t[d]) {
      temp = temp_start + (temp_end - temp_start)*x/climb_loop;
      int diff = s[d][q] - s[d][t[d]];
      int cur = d;
      while(cur <= D && last[cur][t[d]] == d) {
        diff -= c[t[d]] * (d - last[cur-1][t[d]]);
        last[cur][t[d]] = last[cur-1][t[d]];
        cur++;
      }
      cur = d;
      while(cur <= D && last[cur][q] < d) {
        diff += c[q] * (d - last[cur][q]);
        last[cur][q] = d;
        cur++;
      }
      if(diff > 0 || uniform_01(eng) < exp((double)diff/temp)) {
        t[d] = q;
        content += diff;
      } else {
        int day = d;
        while(day <= D && last[day][t[d]] < d) {
          last[day][t[d]] = d;
          day++;
        }
        day = d;
        while(day <= D && last[day][q] == d) {
          last[day][q] = last[day-1][q];
          day++;
        }
      }
    }
  }
  // output
  for(int day = 1; day <= D; day++) cout << t[day]+1 << endl;
  return 0;
}


Measured memory_bytes: 4348
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * (n)
        self.size = [1] * (n)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


N, M = map(int, input().split())
p = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(M)]
uni = UnionFind(N + 1)
for xyi in xy:
    x, y = xyi
    uni.union(x, y)
cnt = 0
for i, pi in enu(p):
    if uni.same_check(i + 1, pi):
        cnt += 1
print(cnt)

Measured memory_bytes: 101732
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int g = sc.nextInt();
		Problem[] array = new Problem[d];
		for (int i = 0; i < d; i++) {
			array[i] = new Problem(100 * (i+1), sc.nextInt(), sc.nextInt());
		}
		sc.close();

		int ans = Integer.MAX_VALUE;
		System.out.println(dfs(d, g, array, "", ans));
	}

	static class Problem {
		int p;
		int c;
		int total;
		public Problem(int s, int p, int c) {
			this.p = p;
			this.c = c;
			this.total = s * p + c;
		}
	}

	static int dfs(int d, int g, Problem[] array, String select, int ans) {
		if (select.length() == d) {
			int total = 0;
			int cnt = 0;
			for (int i = 0; i < d; i++) {
				if (select.charAt(i) == '1') {
					total += array[i].total;
					cnt += array[i].p;
				}
			}
			if (g <= total) {
				return cnt;
			}
			for (int i = d - 1; i >= 0; i--) {
				if (select.charAt(i) == '0') {
					double zanScore = g - total;
					int zanCnt = (int) Math.ceil(zanScore / (100 * (i+1)));
					if (zanCnt < array[i].p) {
						cnt += zanCnt;
					} else {
						cnt = Integer.MAX_VALUE;
					}
					break;
				}
			}
			return cnt;
		}

		ans = Math.min(ans, dfs(d, g, array, select + "0", ans));
		ans = Math.min(ans, dfs(d, g, array, select + "1", ans));
		return ans;
	}
}


Measured memory_bytes: 23892
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vll = V<ll>;
using VVll = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

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

    int cnt = 0;
    char left = ' ';
    FOR(i, s) {
        if (left != *i) {
            cnt++;
            left = *i;
        }
    }
    std::cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#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++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N;
	int a[100000];
	cin >> N;
	rep(i, N) {
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;
	rep(i, N) {
		if (a[a[i]] == i) {
			ans++;
		}
	}
	ans /= 2;
	cout << ans << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(string, s, t);
    t.pop_back();
    cout << (s == t ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 3656
def main():
    N,A,B = map(int, input().split())
    if A == 0:
        print(0)
        return
    
    count=0

    sho1 = N // (A+B)
    amari1 = N % (A+B)
        
    sho2=amari1 // A
    amari2=amari1 % A
    
    if sho1 ==0:
        if sho2 == 0:
            count += amari2
        
        else:
            count += A
    else:
        count += sho1*A
        
        if sho2 == 0:
            count += amari2
        
        else:
            count += A
            

    print(count)
    
    
main()

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

long beki(int n){
    if(n==0) return 1L;
    else return beki(n-1)*10;
}

int main() {
    int n;
    cin>>n;
    string nn=std::to_string(n);
    long ans=0;
    if(nn.length()%2==0){
        for(int i=0;i<nn.length()-1;i+=2){
            ans=ans+beki(nn.length()-i-1)-beki(nn.length()-i-2);
        }
    }else{
        ans=n-beki(nn.length()-1)+1;
        for(int i=1;i<nn.length();i+=2){
            ans=ans+beki(nn.length()-i-1)-beki(nn.length()-i-2);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3680
k, n = map(int, input().split())
a = [int(i) for i in input().split()]

delta = a[0] + (k - a[-1])
for i in range(1, n-1):
    if a[i+1] - a[i] > delta:
        delta = a[i+1] - a[i]
print(k - delta)


Measured memory_bytes: 26444
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]

for i in range(-1, h + 1):
    for j in range(-1, w + 1):
        if i == -1 or j == -1 or i == h or j == w:
            print("#",end = "")
        else:
            print(a[i][j], end="")
    print()


Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  if (s < t) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 3600
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
bool second_smaller(const pll& left, const pll& right) {
    return left.second < right.second;
}
#endif


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

    int N, K; cin >> N >> K;
    vl X(N), Y(N);
    REP(i, N) cin >> X[i] >> Y[i];


    ll ans = LINF;
    REP(i,N) {
        REP(j,N) {
            REP(k,N){
                REP(l,N){
                    if (X[i]<X[j] && Y[k]<Y[l]) {
                        int cnt = 0;
                        REP(m,N) {
                            if (X[i] <= X[m] && X[m] <= X[j] &&
                                Y[k] <= Y[m] && Y[m] <= Y[l]) cnt++;
                        }

                        if (cnt>=K) {
                            ans = min(ans, (X[j] - X[i])*(Y[l] - Y[k]));
                        }
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(void) {
  int n, d, k;
  cin >> n >> d >> k;
  int a[110];
  int count = 0;
  
  for (int i=0; i<n; ++i) cin >> a[i];
  
  for (int i=0; i<n; ++i) {
  	for (int j=0; 1+a[i]*j <= d; ++j) {
      count++;
    }
  }
  
  cout << count+k << endl;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
now=1
ans=0
for i in range(n):
    if a[i]!=now:
        ans+=1
    else:
        now+=1
if ans==n:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 72220
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int N, i;
	float A, x=0.0, y;
	
	scanf("%d", &N);
	lop(i, N){
		scanf("%f", &A);
		y=1.0/A;
		x+=y;
	}
	
	printf("%f", (double)1.0/x);
	
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long int s[1000];
long long int dp[500][500];
void precompute(long long int arr[],int n)
{
    s[0]=arr[0];
    for(int i=1;i<n;i++)
    {
        s[i]=s[i-1]+arr[i];
    }
}
long long int  solve(long long int arr[],int n,int i,int j)
{
    if(i>=j)
    {
        return 0;
    }
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
   long long int ans=9223372036854775807;
    for(int k=i;k<j;k++)
    {
        ans=min(ans,solve(arr,n,i,k)+solve(arr,n,k+1,j)+(s[k]-s[i]+arr[i])+(s[j]-s[k+1]+arr[k+1]));
    }
    return dp[i][j]=ans;
}

int main()
{
    int n;
    memset(dp,-1,sizeof(dp));
    cin>>n;
    long long int  arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    precompute(arr,n);
    long long int ans=solve(arr,n,0,n-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 5596
n,m=map(int,input().split())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
a=make_divisors(m)

ans=[]

for i in a:
  if m//i>=n:
    ans.append(i)
    
print(max(ans))

Measured memory_bytes: 9200
/* ****GT_18**** */

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define INF			1000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
using namespace __gnu_pbds;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		string s;
		cin>>s;
		ll n = sz(s);
		if(s[n-1]=='s'){
			cout<<s<<"es"<<endl;

		}
		else{
			cout<<s<<"s"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
#define int long long

signed main() {
	int dig = -1;//10^p
	for (int i = 0; i < 10; i++) {
		int a = pow(10, i);
		cout << "? " << a << endl;
		char c;
		cin >> c;
		if (c == 'N') {
			dig = i-1;
			break;
		}
	}
	
	if (dig == -1) {
		for (int i = 0; i < 10; i++) {
			int a = pow(10, i) + 1;
			cout << "? " << a << endl;
			char c;
			cin >> c;
			if (c == 'Y') {
				int ans = pow(10, i);
				cout <<"! "<<ans<< endl;
				return 0;
			}
		}
	}
	int lb=pow(10,dig+1), ub=pow(10,dig+2);

	while (ub - lb > 1) {
		int mid = (ub + lb) / 2;
		cout << "? " << mid << endl;
		char c;
		cin >> c;
		if (c == 'Y') {
			ub = mid;
		}
		else lb = mid;
	}
	cout << "! " << ub/10 << endl;
}

Measured memory_bytes: 644
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        var ret0 = culc0m(a);
        var ret1 = culc0p(a ,ret0);
        if (ret1 == -1) Console.WriteLine(ret0);
        else   Console.WriteLine(Math.Min(ret0,ret1));
    }
    public static long culc0m(long[] a)
    {
        var count = 0L;
        var sum = a[0];
        if (sum >= 0) { count += sum + 1; sum = -1; }
        for (int i = 1; i < a.Length; i++)
        {
            if (i % 2 == 1)
            {
                if (sum + a[i] > 0) sum += a[i];
                else { count += -(sum + a[i]) + 1; sum = 1; }
            }
            else
            {
                if (sum + a[i] < 0) sum += a[i];
                else { count += (sum + a[i]) + 1; sum = -1; }
            }
        }
        return count;
    }
    public static long culc0p(long[] a, long b)
    {
        var count = 0L;
        var sum = a[0];
        if (sum <= 0) { count += -sum + 1; sum = 1; }
        for (int i = 1; i < a.Length; i++)
        {
            if (i % 2 == 1)
            {
                if (sum + a[i] < 0) sum += a[i];
                else { count += (sum + a[i]) + 1; sum = -1; }
            }
            else
            {
                if (sum + a[i] > 0) sum += a[i];
                else { count += -(sum + a[i]) + 1; sum = 1; }
            }
            if (count > b) return -1;
        }
        return count;
    }
}

Measured memory_bytes: 27228
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100)
#define MAX_T (200)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, ts[MAX_N], vs[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &ts[i]);
  }
  for (int i = 0; i < N; i++) {
    scanf("%d", &vs[i]);
  }

  // calculate accumulated time
  int taccs[MAX_N + 1];
  taccs[0] = 0;
  for (int i = 0; i < N; i++) {
    taccs[i + 1] = taccs[i] + ts[i];
  }

  // calculate the maximum velocity for each time step (0.5s)
  double max_velocities[2 * MAX_N * MAX_T + 1];
  double limit_velocities[2 * MAX_N * MAX_T + 1];
  int segment = N - 1;
  max_velocities[2 * taccs[N]] = 0;
  limit_velocities[2 * taccs[N]] = vs[segment];
  for (int t = 2 * taccs[N] - 1; t >= 0; t--) {
    double limit_velocity;
    if (segment > 0 && t == 2 * taccs[segment]) {
      limit_velocity = min(vs[segment], vs[segment - 1]);
      segment--;
    } else {
      limit_velocity = vs[segment];
    }
    max_velocities[t] = min(max_velocities[t + 1] + 0.5, limit_velocity);
    limit_velocities[t] = limit_velocity;
  }

  // determine the velocity for each time step
  double velocities[MAX_N * MAX_T + 1];
  velocities[0] = 0;
  for (int t = 1; t <= 2 * taccs[N]; t++) {
    velocities[t] = min(velocities[t - 1] + 0.5, max_velocities[t]);
  }

  // for (int t = 0; t <= taccs[N]; t++) {
  //   printf("t = %3lf, v = %5lf, max_v = %5lf, limit_v = %lf\n", t / 2.0,
  //          velocities[t], max_velocities[t], limit_velocities[t]);
  // }

  // calculate the distance traveled
  double d = 0;
  for (int t = 1; t <= 2 * taccs[N]; t++) {
    d += velocities[t] + velocities[t - 1];
  }
  d *= 0.25;
  printf("%.5lf\n", d);

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=2077;
ll dp[mx][mx];

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<ll> A(N);
	for (int i=0; i<N; i++)
		cin>>A[i];
	multiset<ii> mst;
	for (int i=0; i<N; i++)
		mst.insert({A[i],i+1});
	ii init=*mst.rbegin(); mst.erase(mst.find(init));
	dp[0][0]=abs(init.second-N)*init.first;
	dp[0][1]=abs(init.second-1)*init.first;
	for (int i=1; i<N; i++) {
		ii cur=*mst.rbegin(); mst.erase(mst.find(cur));
		dp[i][0]=dp[i-1][0]+abs(cur.second-(N-i))*cur.first;
		dp[i][i+1]=dp[i-1][i]+abs(cur.second-(i+1))*cur.first;
		for (int j=1; j<=i; j++) {
			int left=j,right=N-(i-j);
//			cout<<i<<" "<<j<<"::"<<left<<" "<<right<<endl;
//			cout<<i<<" "<<j<<"::RIGHT="<<dp[i-1][j]<<"+|"<<cur.second<<"-"<<right<<"|*"<<cur.first<<" LEFT="<<dp[i-1][j-1]<<"+|"<<cur.second<<"-"<<left<<"|*"<<cur.first<<endl;
			dp[i][j]=max(dp[i-1][j]+abs(cur.second-right)*cur.first,dp[i-1][j-1]+abs(cur.second-left)*cur.first);
		}

//		for (int j=0; j<=i+1; j++)
//			cout<<i<<" "<<j<<"::"<<dp[i][j]<<endl;
	}
/*
	for (int i=0; i<N; i++)
		for (int j=0; j<=i+1; j++)
			cout<<i<<" "<<j<<"::"<<dp[i][j]<<endl;
*/

	ll ret=0;
	for (int i=0; i<=N; i++)
		ret=max(ret,dp[N-1][i]);
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 26680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B,plan1;
  cin >> N >> A>> B;
  plan1=N*A;
  if (plan1<=B) {
    cout << plan1 << endl;
  }else{
    cout << B << endl;
  }  
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::string s, t;

    std::cin >> s >> t;

    for(int i = 0; i < n; i++){
        std::cout << s.at(i) << t.at(i);
    }
    std::cout << std::endl;

    return 0;
}


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

ans = []
x1 = sum(a) - 2 * sum([a[i] for i in range(1, n, 2)])
ans.append(x1)
for i in range(n-1):
    ans.append(2 * a[i]-ans[-1])

print(*ans)




Measured memory_bytes: 14092
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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

	cout << min(A*N, B) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

std::vector<int> Stone;
int main() {
    int N;
    std::cin >> N;
    for(int i=0;i<N;i++){
        char color;
        std::cin >> color;
        if(color == 'W')
            Stone.push_back(0);
        else
            Stone.push_back(1);
    }
    int ope=0;
    int cur_left=0,cur_right=N-1;
    while(true) {
        while (Stone[cur_left] != 0 && cur_left < N) {
            cur_left++;
        }
        while (Stone[cur_right] != 1 && cur_right >= 0) {
            cur_right--;
        }
        if (cur_left >= N || cur_right < 0 || cur_right < cur_left) {
            break;
        }
        Stone[cur_right] = 0;
        Stone[cur_left] = 1;
        ope++;
    }
    std::cout << ope;
    return 0;
}

Measured memory_bytes: 4272
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7
n, m = map(int, input().split())
# 幅優先？
ans = [-1 for i in range(n)]  # i+1番目の部屋にある道しるべ
visited = [False for i in range(n)]
visited[0] = True
dicab = {}
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a in dicab.keys():
        dicab[a].append(b)
        if b in dicab.keys():
            dicab[b].append(a)
        else:
            dicab[b] = [a]
    else:
        dicab[a] = [b]
        if b in dicab.keys():
            dicab[b].append(a)
        else:
            dicab[b] = [a]


def bfs():
    q = deque([0])
    while q:
        now = q.popleft()
        nlist = dicab[now]
        for nextnode in nlist:
            if visited[nextnode] == False:
                visited[nextnode] = True
                ans[nextnode] = now
                q.append(nextnode)


bfs()
ans[0] = 0
print('Yes')
for i in range(1, n):
    print(ans[i] + 1)

Measured memory_bytes: 106584
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
    x_minus = x%(m-1)
else:
    x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

Measured memory_bytes: 92848
#include<stdio.h>
#include<math.h>
int main()
{
    int x,a,b,n,m,i,j;
    while(scanf("%d%d%d",&x,&a,&b)!=EOF){
        if(a==b){return 0;}
        n=fabs(x-a);
        m=fabs(x-b);
        if(n<m){
            printf("A\n");
        }
        else{
            printf("B\n");
        }
    }
    return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c;
    
    if (a > b){
        d = a;
        a = b;
        b = d;
        if (b > c){
            d = b;
            b = c;
            c = d;
            if (a > b){
                d = a;
                a = b;
                b = d;    
            }
        }
    }else if (b > c){
        d = b;
        b = c;
        c = d;
    }
    cout << a <<" "<< b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3100
#include "stdio.h"

int main(int argc, char const *argv[]) {
  int n=0;
  char s[4];
  for(int i=0; i<4; i++){
    scanf("%s",&s[i] );
  }
  for(int i=0; i<4; i++){
    if(s[i]=='+') n++;
    else if(s[i]=='-') n--;
  }
  printf("%d",n );
  return 0;
}


Measured memory_bytes: 128
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
print(len(list(filter(lambda x: len(make_divisors(x)) == 8, range(1, n + 1,2)))))


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+7;
int a[N],b[N];
int ans,n;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++) scanf("%d",&b[i]);
	a[1]=b[1];
	for (int i=2;i<n;i++) a[i]=min(b[i-1],b[i]);
	a[n]=b[n-1];
	for (int i=1;i<=n;i++) ans+=a[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()
 
#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V){
  os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
} 

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}


#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
 
#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
 
#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb fflush(stdout)
 
const int max_n = 1e5 + 5;
 



int main() {
	make2(x,y);
	make2(a,b);
	if (x%a== 0 && y%b==0) {
		printf("No\n");
		return 0;
	} else {
		printf("Yes\n");
		int t = 1e9/(a*b);
		FOR(i,0,x) {
			FOR(j,0,y) {
				if (i%a == a-1 && j%b == b-1) {
					printf("%d ", -(a*b-1)*t-1);
				} else {
					printf("%d ", t);
				}
			}
			printf("\n");
		}
	}
}


Measured memory_bytes: 2816