akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

void solve() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> to(N+1);
  vector<vector<int>> from(N+1);
  vector<bool> visited(N+1);
  vector<int> parent(N+1);


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

  int root = 1;
  while (!to[root].empty()) {
    root++;
  }

  visited[root] = true;
  parent[root] = 0;

  queue<int> q;
  q.push(root);

  while (!q.empty()) {
    int x = q.front(); q.pop();
    visited[x] = true;

    for (int dist : from[x]) {
      bool ok = true;
      for (int y : to[dist]) {
        if (!visited[y]) {
          ok = false;
          break;
        }
      }
      if (ok) {
        q.push(dist);
        parent[dist] = x;
      }
    }
  }

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

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


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

bool cnt(int n){
    int tmp = 0;
    while (n > 0){
        tmp++;
        n /= 10;
    }
    return tmp % 2;
}

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (cnt(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007


ll power(ll x, ll y) 
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return (temp*temp)%mod;
    else
        return (((x*temp)%mod)*temp)%mod; 
}
int fact[1000005];
int invfact[1000005];
int inv(int N){
    return power(N,mod-2);
}
ll nCr(ll n, ll r){
    if(r<0 || n<0)return 0;
    if(n<r) return 0;
    ll a=fact[n];
    a=(a*invfact[r])%mod;
    a=(a*invfact[n-r])%mod;
    return a;
}
void init(){
    fact[0]=1;
    invfact[0]=1;
    for(int i=1;i<1000005;i++){
        fact[i]=(i*fact[i-1])%mod;
        invfact[i]=inv(fact[i]);
    }
}


int32_t main(){
	ios::sync_with_stdio(false);
    init();
    int n;
    cin>>n;
    ll ans=(n-1)*fact[n-1];
    ans=ans%mod;
    int k=n-2;
    for(int i=1;i*2<=k;i++){
        int cur=fact[k-i];
        cur=(cur*fact[n-1-i])%mod;
        cur=(cur*invfact[k-2*i])%mod;
        ans-=cur;
        ans=ans%mod;
    }
    if(ans<0)ans+=mod;
    cout<<ans<<"\n";



	return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define ll long long

using namespace std;



	

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

	ll n,k;cin>>n>>k;

	if(k >= n)
		cout<<min(n,k-n);

	else
		cout<<min(n%k,k - (n%k));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;b >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    int n; cin >> n;
    int k = n % 10;
    if(k == 3) {
        cout << "bon";
    }
    else if(k == 0 || k == 1 || k == 6 || k == 8) {
        cout << "pon";
    }
    else {
        cout << "hon";
    }
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long int li;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
  ll ans=0;
  ll n,m;
  ll l,r;
  l=-10;
  r=10000000;
  cin >> n >> m;
  for(ll i=1;i<=m;i++){
  	ll x,y;
    cin >> x >> y;
    l=max(l,x);
    r=min(r,y);
  }
  ans=r-l+1;
  if(ans<=0)ans=0;
  	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int A[100],N,a,i,j,minj,temp,count=0,k,l;
  scanf("%d",&N);
    for(a=0;a<N;a++){
      scanf("%d",&A[a]);
    }
    for(i=0;i<=N-1;i++){
      minj=i;
      l=i;
      for(j=i+1;j<N;j++){
	if(A[j]< A[minj]){
	  minj=j;
	}
	
      }
      
      if(l!=minj){
	temp=A[i];
	A[i]=A[minj];
	A[minj]=temp;
	
	
	count++;
      }
    
    
 

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

return 0;
}






Measured memory_bytes: 2124
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long
signed main() {
  int n;
  cin >> n;

  int a[n];
  rep(i,n) cin >> a[i];

  if(n%2==0) {
    rep(i,n/2) cout << a[n-1-i*2]<<" " << flush;
    rep(i,n/2) cout << a[i*2]<<" " << flush;
  }else {
    rep(i,n/2+1) cout << a[n-1-i*2]<<" " << flush;
    rep(i,n/2) cout << a[i*2+1]<<" " << flush;
  }
  return 0;
}


Measured memory_bytes: 5132
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll row[107],col[107];

int main() {
  ll N;cin >> N;
  ll j=0,i=25;
  while(i>=0){
    if(i*4+j*7>N){
      i--;
      continue;
    }
    if(i*4+j*7<N){
      j++;
    }
    if(i*4+j*7==N){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define ZERO(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

string s1,s2,s3;

int main() {
    cin>>s1>>s2>>s3;
    int c1,c2,c3;
    c1 = c2 = c3 = 0;
    int n1 = SZ(s1);
    int n2 = SZ(s2);
    int n3 = SZ(s3);
    char a='A';
    string ans="";
    while(1) {
        if(a=='A') {
            if(c1 == n1) {
                ans = 'A'; break;
            }
            if(s1[c1] == 'a') a='A';
            if(s1[c1] == 'b') a='B';
            if(s1[c1] == 'c') a='C';
            c1++;
        }
        if(a=='B') {
            if(c2 == n2) {
                ans = 'B'; break;
            }
            if(s2[c2] == 'a') a='A';
            if(s2[c2] == 'b') a='B';
            if(s2[c2] == 'c') a='C';
            c2++;
        }
        if(a=='C') {
            if(c3 == n3) {
                ans = 'C'; break;
            }
            if(s3[c3] == 'a') a='A';
            if(s3[c3] == 'b') a='B';
            if(s3[c3] == 'c') a='C';
            c3++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

struct union_find{
    union_find(int n){
        for(int i=0; i<=n; i++){
            par.push_back(i);
            size.push_back(1);
        }
    }
    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(size[x] > size[y]) swap(x, y); 
        par[x] = y;
        size[y]+= size[x];
    }
    int getSize(int x){
        return size[find(x)];
    }

    private:
        vector<int> par, size;
};

int main(){
    ll N, M;
    cin >> N >> M;
    vector<pair<int,int>> bridge(M+1);
    for(int i=1; i<=M; i++){
        int A, B;  cin >> A >> B;
        bridge[i] = make_pair(A, B);
    }

    union_find island(N);
    vector<ll> conv(M+2,0); // 橋 i 建設後の便利さ = conv[i]
    conv[M+1] = 0; // 橋が 1 つも無いとき便利さは 0

    // 橋 M, M-1, ……, 1 の順に橋を建設する
    for(int i=M; i>=0; i--){
        int A = bridge[i].first;
        int B = bridge[i].second;
        // A と B の根を求める
        A = island.find(A);
        B = island.find(B);
        if(A==B){
            // A, B が互いに行き来できるとき、AとBを繋いでも便利さは増えない
            conv[i] = conv[i+1];
        }else{
            // A, B が互いに行き来できないとき、
            // A, B の各グループの連結成分の数の積だけ便利さが増える
            conv[i] = conv[i+1] + island.getSize(A)*island.getSize(B);
        }
        // A と B を併合
        island.unite(A,B);
    }

    // （橋 i 崩落後の不便さ）+（橋 i + 1 建設後の便利さ）= N*(N-1)/2
    for(int i=1; i<=M; i++){
        ll ans = N*(N-1)/2 - conv[i+1];
        cout << ans << endl;
    }
}


Measured memory_bytes: 3828
n=int(input())
f=[0]*n
p=[0]*n
INF=10**9
for i in range(n):
    f[i]=list(map(int,input().split()))
for i in range(n):
    p[i]=list(map(int,input().split()))
ans=-INF
for i in range(1,1<<10):
    cnt=0
    l=[0]*n
    for j in range(10):
        if (i>>j)%2==1:
            for h in range(n):
                if f[h][j]==1:
                    l[h]+=1
    x=0
    for i in range(n):
        x+=p[i][l[i]]
    ans=max(x,ans)
print(ans)

Measured memory_bytes: 3064
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	int a, b, c;
	vector<int> x(3);
	rep(i, 3) cin >> x[i];
	sort(x.begin(), x.end());

	int cnt = 0;
	bool second = false;
	while (x[1] < x[2]) {
		x[0]++;
		x[1]++;
		cnt++;
	}
	if((x[1]-x[0])%2==0) cnt += (x[2] - x[0]) / 2;
	else {
		x[1]++;
		cnt++;
		cnt += (x[1] - x[0]) / 2;
	}
	cout << cnt << endl;
	return 0;
}


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

// s の方が大きいときに true
string max_s(const string &s, const string &t) {
    if(s.length() != t.length()) return (s.length() > t.length() ? s : t);
    else return (s > t ? s : t);
}

string min_s(const string &s, const string &t) {
    if(s.length() != t.length()) return (s.length() < t.length() ? s : t);
    else return (s < t ? s : t);
}

string dp[60][60], pat = "LR";
int main() {
    string s; cin >> s;
    int N = (int)s.length();

    for(int len=1; len<=N; len++) {
        for(int l=0; l<N-len+1; l++) {
            int r = l + len;
            // ただの数字
            bool can_num = true;
            string nxt = "";
            for(int i=l; i<r; i++) {
                if(r-l > 1 && i == l && s[i] == '0') can_num = false;
                else if(s[i] != '?' && !isdigit(s[i])) can_num = false;
                else if(s[i] == '?') nxt += '9';
                else nxt += s[i];
            }
            if(can_num) {
                dp[l][r] = max_s(dp[l][r], nxt);
            }

            // 左端を L or R にして括弧
            // カンマの位置を全部ためそう
            for(int t=0; t<2; t++) {
                if(s[l] == pat[t] || s[l] == '?') {
                    if(r-l < 6) continue;
                    if(s[l+1] != '?' && s[l+1] != '(') continue;
                    if(s[r-1] != '?' && s[r-1] != ')') continue;
                    for(int k=l+2; k<r-1; k++) {
                        if(s[k] != ',' && s[k] != '?') continue;
                        string v1 = dp[l+2][k];
                        string v2 = dp[k+1][r-1];
                        if(v1 == "" || v2 == "") continue;
                        string tmp = (pat[t] == 'L' ? v1 : v2);
                        dp[l][r] = max_s(dp[l][r], tmp);
                    }
                }
            }

            /*
            if(dp[l][r] != "") {
                cout << s << endl;
                for(int i=0; i<N; i++) {
                    if(l <= i && i < r) printf("=");
                    else printf(" ");
                }
                printf(" -> %s\n\n", dp[l][r].c_str());
            }
            */
        }
    }

    if(dp[0][N] == "") cout << "invalid" << endl;
    else cout << dp[0][N] << endl;
    return 0;
}


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

int r, c;

int main() {
    cin >> r >> c;
    int rc[101][101] = {0};
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> rc[j][i];
        }
    }
    
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < r; j++) {
            rc[i][r] += rc[i][j];
        }
    }
    
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            rc[c][i] += rc[j][i];
        }
    }
    
    for (int i = 0; i < c; i++) {
        rc[c][r] += rc[i][r];
    }
    
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cout << rc[j][i]<< " ";
        }
        cout << rc[c][i] << endl;
        
    }
    for (int i = 0; i < c; i++) {
        cout << rc[i][r] << " ";
    }
    cout << rc[c][r] << endl;
    
    return 0;
}




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

typedef long long LL;

const int N=1000000,mod=998244353,inv2=499122177;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,cnt[N+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
	int x;
	scanf("%d",&x);
	++cnt[x];
  }
}

int inv[N+9];

void Get_inv(){
  inv[1]=1;
  for (int i=2;i<=N;++i) inv[i]=mul(mod-mod/i,inv[mod%i]);
}

int sum[N+9],ans;

void Get_ans(){
  for (int i=N;i>=1;--i){
	int now=0;
	for (int j=i;j<=N;j+=i) sadd(now,mul(cnt[j],j));
	sum[i]=mul(now,now);
	for (int j=i<<1;j<=N;j+=i) ssub(sum[i],sum[j]);
	sadd(ans,mul(sum[i],inv[i]));
	ssub(ans,mul(cnt[i],i));
  }
  smul(ans,inv2);
}

void work(){
  Get_inv();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 15556
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		long n = parseLong(sc.next());
		long k = parseLong(sc.next());
		sc.close();
		long ans = (long) (k * pow(k-1,n-1));
		out.println(ans);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    ll a,b,x;cin>>a>>b>>x;
    if(a!=0) cout<<b/x-(a-1)/x<<endl;
    else cout<<b/x+1<<endl;
}

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


void solve(){

}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin >> a >> b;
    int ct=0, aa=1;
    while(aa < b){
        --aa;
        aa += a;
        ++ct;
    }
    cout << ct << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200005
#define ll long long
using namespace std;
vector<int>a[N];
int f[N], v[N];
priority_queue<pair<int, int>>q;
int main(){
    int n, m;
    cin>>n>>m;
    for(int i=1; i<=n; ++i){
        for(int j=1; j<=m; ++j){
            char c;
            cin>>c;
            f[(i-1)*m+j]=(c=='#');
            if(i!=n){
                a[(i-1)*m+j].push_back(i*m+j);
            }
            if(j!=m){
                a[(i-1)*m+j].push_back((i-1)*m+j+1);
            }
        }
    }
    q.push({-1-f[1], 1});
    v[1]=1;
    while(!q.empty()){
        int j=q.top().first;
        int i=q.top().second;
        if(i==m*n){
            cout<<-j-1;
            return 0;
        }
        v[i]=-v[i];
        for(auto it:a[i]){
            int cct=j;
            if(f[it] && !f[i]){
                cct--;
            }
            if(!v[it] || v[it]>-cct){
                v[it]=-cct;
                q.push({cct, it});
            }
        }
        while(!q.empty() && v[q.top().second]<0){
            q.pop();
        }
    }
    return 0;
}

Measured memory_bytes: 5376
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class B_168_TripleDots
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            long K = long.Parse(Console.ReadLine());
            // 文字列の入力
            string S = Console.ReadLine();

            string result = "";

            if (S.Length <= K)
            {
                Console.WriteLine(S);
            }else
            {
                for (int i = 0; i < K; i++)
                {
                    result += S[i];
                }
                result += "...";

                Console.WriteLine(result);
            }


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27496
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){
int N,M;cin>>N>>M;
vector <int> box(100);
for(int i=0;i<N;i++){
  int K;cin>>K;
  for(int j=0;j<K;j++){
    int A;cin>>A;
    box[A]++;
  }
}

int ans=0;

for(int i=0;i<100;i++){
  if(box[i]==N) ans++;

}

cout<<ans<<endl;

  return 0;
}
  


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

int main(void){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    
    vector<int> nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; i++){
        if (S[i] == (char)(now + '0')) cnt++;
        else{
            nums.push_back(cnt);
            cnt = 1;
            now = 1 - now;
        }
    }
    if (cnt != 0) nums.push_back(cnt);
    
    if (nums.size() % 2 == 0) nums.push_back(0);
    
    vector<int> sums(nums.size() + 1);
    for (int i = 0; i < nums.size(); i++){
        sums[i + 1] = sums[i] + nums[i];
    }
    
    int Add = 2 * K + 1;
    int ans = 0;
    for (int i = 0; i < nums.size(); i += 2){
        int left = i;
        int right = min(i + Add, (int)(nums.size()));
        int tmp = sums[right] - sums[left];
        ans = max(ans, tmp);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int A;
  int B;
  cin >>N>>A>>B;
  int x=N*A;
  int y=B;
  int z=min(x,y);
  cout << z<< endl;
}
  

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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
using V = vector<ll>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll hcnt[300005],wcnt[300005];

int main() {
  int N,K;
  cin>>N>>K;
  vector<int> v(N);
  rep(i,N) cin>>v[i];
  sort(v.begin(),v.end());
  int ans = 0;
  rep(i,K) ans += v[i];
  cout<<ans<<endl;
}

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

int main(void)
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    int count=0;
    for (int i = 0; i < N; i++){
        if (s.at(i)=='W')
        {
            count++;
        }
    }
    int ans=0;
    for (int i = 0; i < N-count; i++){
        if (s.at(i)=='W')
        {
            ans++;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3752
#include <stdio.h>
main(){
  int i,j,n,a[401][401],ni,di,k,d[4],xmax,xmin,ymax,ymin,jud;
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    xmax=200;
    xmin=200;
    ymax=200;
    ymin=200;
    for(i=0;i<401;i++){
      for(j=0;j<401;j++) a[i][j]=-1;
    }
    for(i=0;i<4;i++) d[i]=0;
    a[200][200]=0;

    for(i=1;i<n;i++){
      scanf("%d%d",&ni,&di);
      jud=0;
      for(j=200-d[0] ; j<=200+d[2] ; j++){
	for(k=200-d[1] ; k<=200+d[3] ; k++){
	  if(a[j][k] == ni){
	    if(di == 0){
	      a[j-1][k] = i;
	      if(j-1 < xmin){
		xmin = j-1;
		d[0]++;
	      }
	    }
	    else if(di == 1){
	      a[j][k-1] = i;
	      if(k-1 < ymin){
		ymin = k-1;
		d[1]++;
	      }
	    }
	    else if(di == 2){
	      a[j+1][k] = i;
	      if(j+1 > xmax){
		xmax = j+1;
		d[2]++;
	      }
	    }
	    else if(di == 3){
	      a[j][k+1] = i;
	      if(k+1 > ymax){
		ymax = k+1;
		d[3]++;
	      }
	    }
	    jud=1;
	    break;
	  }
	}
	if(jud == 1) break;
      }
    }


    printf("%d %d\n",xmax-xmin+1,ymax-ymin+1);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <cstdio>
#include <string>
#include <utility>
#include <iomanip>
#include <numeric>
#include <functional>
#include <list>
#include <regex>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <climits>
using namespace std;


typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;

#define pb(c,num) c.push_back(num)

// loops
#define rep(i,n) for (int i = 0; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define tr(c, it) \
for(auto it = c.begin(); it != c.end(); ++it)


#define all(c) c.begin(), c.end()

// set,map
#define present(c, element) (c.find(element) != c.end())
//vectors
#define cpresent(c, element) (find(all(c), element) != c.end())




int main(){
    std::ios_base::sync_with_stdio(false);

//    ifstream input;
//    ofstream output;
//    input.open("input.in");
//    output.open("output.out");
    

    int N;
    cin >> N;

    if(N == 1){
        cout << 1;
        return 0;
    }
    else{
    int counter = 0;
    for(int i = 1; i <= N; ++i){
        if(i%2 == 1)
            counter++;
    }

    printf("%.6lf", double(counter)/N);
    
    }
//    input.close();
//    output.close();
//
    
    return 0;
}
    


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 200100;
int a[N], n;

int solve() {
	int cur = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] == cur) cur++;
	}
	cur--;
	if (cur == 0) return -1;
	return n - cur;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	printf("%d\n", solve());
}



Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	static int max;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<String> list = new ArrayList<String>();
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		for(int i = 0; i < n; i++) {
			String a = sc.next();
			int b = sc.nextInt();
			if(map.containsKey(a)) map.put(a, map.get(a) + b);
			else {
				list.add(a);
				map.put(a, b);
			}
		}
		Collections.sort(list,new Comp());
		
		for(int i = 0; i < list.size(); i++) { 
			System.out.println(list.get(i) + " " + map.get(list.get(i)));
		}
		
	}
	static class Comp implements Comparator<String> {

		@Override
		public int compare(String o1, String o2) {
			if(o1.length() != o2.length()) return o1.length() - o2.length();
			for(int i = 0; i < o1.length(); i++) {
				if(o1.charAt(i) == o2.charAt(i)) continue;
				return o1.charAt(i) - o2.charAt(i);
			}
			return 0;
		}
		
		
	}
}

Measured memory_bytes: 38612
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
 
		String s = sc.next(), h = "pg";
 
		int cnt = 0, n = s.length();
		for (int i = 0; i < n; i++) cnt += s.charAt(i) == h.charAt(i%2) ? (i % 2 == 0 ? -1 : 1) * 1 : 0;
 
		System.out.println(cnt);
	}
}

Measured memory_bytes: 13860
#include<iostream>

using namespace std;

int main(){
  int n, a[3][109], sm[3][109];
  cin >> n;
  for(int i=0;i<2;i++){
    for(int j=0;j<n;j++){
      cin >> a[i][j];
    }
  }
  sm[0][0] = a[0][0];
  for(int j=1;j<n;j++){
    sm[0][j] = sm[0][j-1]+a[0][j];
  }
  sm[1][0] = sm[0][0] + a[1][0];
  for(int j=1;j<n;j++){
    sm[1][j] = max(sm[1][j-1], sm[0][j])+a[1][j];
  }
  cout << sm[1][n-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll mx = 1e5 + 10;
  ll n;
  cin >> n;
  vl a(mx, 0);
  rep(i, n) {
    ll c;
    cin >> c;
    a[c]++;
  }
  vl sum(mx + 1, 0);
  rep(i, mx) sum[i + 1] = sum[i] + a[i];
  ll ans = 0;
  rep(i, mx - 3) ans = max(ans, sum[i + 3] - sum[i]);
  cout << ans << endl;
}

Measured memory_bytes: 1792
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    if(a[m-1]*(4*m) < sum){
        cout << "No" << "\n";
    }else{
        cout << "Yes" << "\n";
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vll p(n);
	for (ll i = 0; i < n; i++) cin >> p[i];

	vll q(n);
	for (ll i = 0; i < n; i++) q[p[i] - 1] = i;

	ll cnt = 0;
	for (ll i = 0; i < n; i++) {
		ll j = i + 1;
		while (j < n && q[j - 1] < q[j]) j++;
		cnt = max(cnt, j - i);
		i = j - 1;
	}

	cout << n - cnt << endl;
}


Measured memory_bytes: 3456
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var size_list = new List<int>();
            for (int k=0; k<N; k++)
            {
                size_list.Add(cin.ReadInt);
            }
            IEnumerable<int> result = size_list.Distinct();
            int answer = result.Count();
            WriteLine(answer);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
#include<string.h>
int main(){
    char moji1[101] = {}, moji2[101] = {};
    int i, r, n, p1 = 0, p2 = 0;
    scanf("%d", &n);
    for( i = 0; i < n; i++ ){
        (void)getchar();
       scanf("%s %s", moji1, moji2);
 //      printf("%s %s\n", moji1, moji2);
       if( strcmp( moji1, moji2 ) == 0 ){
           p1 += 1;
           p2 += 1;
       }else{
            for( r = 0; r < strlen( moji1 ); r++ ){
                if( (int)moji1[r] > (int)moji2[r] ){
                    p1 += 3;
 //                   printf("%c %ci\n", moji1[r], moji2[r]);
                    break;
                }else if( (int)moji1[r] < (int)moji2[r] ){
                    p2 += 3;
 //                   printf("%c %c\n", moji1[r], moji2[r]);
                    break;
                }else if( r == strlen( moji1 )-1 ){
                    p2 += 3;
                }
            }
       }
    }
    printf("%d %d\n", p1, p2);
 //   printf("%s %s", moji1, moji2);
    return 0;
}

Measured memory_bytes: 608
n,q=map(int,input().split())
s=input()
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=map(int,input().split())

ac=[0]*n #0番目からn番目までの部分文字列でacがいくつつくれるか
ac[0]=0
def isac(i):
  if s[i]=='A' and s[i+1]=='C':
    return 1
  else:
    return 0
ac[1]=isac(0)
for i in range(n-1):
    ac[i+1] = ac[i] + isac(i)
for i in range(q):
  print(ac[r[i]-1]-ac[l[i]-1])


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

int main() {
    int H, W;
    cin >> H >> W;
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    
    int clr = 0;
    vector<vector<int>> grid(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (a[clr] == 0) clr++;
            if (i % 2 == 0) grid[i][j] = clr + 1;
            else grid[i][W-1-j] = clr + 1;
            a[clr]--;
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j < W-1) printf("%d ", grid[i][j]);
            else printf("%d\n", grid[i][j]);
        }
    }
}

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

int main(){
	while(1){
		int ans=0;
		int n;
		cin>>n;
		if(cin.eof())break;
		for(int a=0;a<=9;a++){
			for(int b=0;b<=9;b++){
				for(int c=0;c<=9;c++){
					for(int d=0;d<=9;d++){
						if(a+b+c+d==n)ans++;
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
    cin >>n;
    vector<int>p(n);
    for(int i=0;i<n;i++)cin>>p[i];
    int ans=0;
    int curMin=10e8;
    for(int i=0;i<n;i++){
      curMin =min(curMin,p[i]);
      if(curMin == p[i])ans++;}
      cout<<ans<<endl;
    }
    

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

int main(void){
	int N;
	cin >> N;
	int a[N+1];
	int tmp;
	rep(i,N) {
		cin >> tmp;
		a[tmp] = i+1;
	}
	for (int i = 1; i <= N; i++) {
		cout << a[i] << endl;
	}


	return 0;
}


Measured memory_bytes: 3912
#include <stdio.h>

#define STATION_NUM 3

int main() {
	char S[STATION_NUM];
	short i, cnt = 0;

	scanf("%s", S);
	for (i = 0; i < STATION_NUM; i++) {
		if (S[i] == 'A') {
			cnt++;
		}
	}
	if (cnt == 0 || cnt == 3) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void) {
  ll d, g;
  cin>>d>>g;
  vector<pair<ll, ll>> v;
  for(int i=0; i<d; i++){
    ll x, y;
    cin>>x>>y;
    v.push_back(make_pair(x, y));
  }

  ll ans = 10*1000;
  for(int b=0; b<(1<<d); b++) {
    ll p = 0;
    ll num = 0;
    for(int i=0; i<d; i++) {
      if(b & (1<<i)) {
	p += v[i].first*(i+1)*100 + v[i].second;
	num += v[i].first;
      }
    }
    if (p >= g) {
      ans = min(ans, num);
    } else {
      for (int i=d-1; i>= 0; i--) {
	if (!(b & (1<<i))) {
	  for (int j = 1; j < v[i].first and p < g; j++) {
	    p+= (i+1)*100;
	    num++;
	  }
	  if (p >= g) {
	    ans = min(ans, num);
	    break;
	  }
	}
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a[] = new int[3];
    for(int i = 0;i<3;i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int dis = 0;
    for(int i = 0;i<2;i++){
      dis += a[i+1] - a[i];
    }
    System.out.println(dis);
  }
}


Measured memory_bytes: 23508
#include <iostream>
using namespace std;
int n,a[240001],ans;
string s,t;
int f(string s){
    int S=(s[0]-'0')*100000+(s[1]-'0')*10000+(s[3]-'0')*1000+(s[4]-'0')*100+(s[6]-'0')*10+(s[7]-'0');
    return S;
}
int main(void){
    while(1){
    cin>>n;
    if(n==0)return 0;
    for(int i=0;i<=240000;i++)a[i]=0;
    for(int i=0;i<n;i++){
        cin>>s>>t;
        //cout<<f(s)<<endl;
        a[f(s)]+=1;
        a[f(t)]+=-1;
    }
    ans=a[0];
    for(int i=0;i<240000;i++){
        a[i+1]+=a[i];
        ans=max(ans,a[i+1]);
    }
    cout<<ans<<endl;
    }
}



Measured memory_bytes: 4104
$n=<>;
$s{substr(<>,0,1)}++for(1..$n);
@p=(M,M,M,M,M,M,A,A,A,R);
@q=(A,A,A,R,R,C,R,R,C,C);
@r=(R,C,H,C,H,H,C,H,H,H);
$o+=$s{$p[$_]}*$s{$q[$_]}*$s{$r[$_]}for(0..9);
print$o

Measured memory_bytes: 512
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
int a,b,c,ans;
int main(){
	cin>>a>>b>>c;
	ans=min(abs(a-b)+abs(b-c),min(abs(a-c)+abs(b-c),abs(b-c)+abs(a-c)));
	ans=min(ans,min(abs(b-a)+abs(a-c),min(abs(c-a)+abs(a-b),abs(c-b)+abs(b-a))));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, t, a[100001], ma[100001], d[100001];
int main() {
  cin >> n >> t; read_n(a, n);
  
  ma[0] = a[0];
  for (lli i=1; i<n; ++i) ma[i] = min(ma[i-1], a[i]);

  for (lli i=1; i<n; ++i) {
    d[i] = a[i] - ma[i-1];
  }

  sort(&d[0], &d[n], greater<lli>());
  lli ans = 1;
  lli x = d[0];
  for (lli i=1; i<n; ++i) {
    if (x == d[i]) ++ans;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

std::string s;
int a, b;
int A[1000];
int B[1000];
int main() {
    cin >> a >> b;
    int x = b-a;
    A[0] = 1;
    B[0] = 0;
    rep(i, 1, 1000) {
        A[i] = A[i-1] + (i+1);
    }
    cout << A[x-1]-b << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
before = 10**3
ans = 0
for i in A:
    if i - before == 1:
        ans += C[before-1]
    before = i
ans += sum(B)
print(ans)

Measured memory_bytes: 38384
h,w,n,*a = map(int,open(0).read().split())
b = []
for i in range(len(a)):
  b += [i+1]*a[i]
for i in range(h):
  if i % 2 == 0:
    print(*b[i*w:(i+1)*w])
  else:
    print(*b[i*w:(i+1)*w][::-1])

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

int main() {
	int W,H,x,y,r;
	char buf[512];
	int y_n=1; //yes=1,no=0
	
	fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d %d %d %d %d", &W, &H, &x, &y, &r);
    
    if(x-r<0 || x+r>W) y_n=0;
    if(y-r<0 || y+r>H) y_n=0;
    
    if(y_n==1) printf("%s\n", "Yes");
    else printf("%s\n", "No");
	
	return 0;
}

Measured memory_bytes: 3160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = Integer.parseInt(sc.next());
		sc.close();

		int util = 0;
		util += (X / 500) * 1000;
		int rest = X % 500;
		util += (rest / 5) * 5;
		System.out.println(util);

	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  while(1){
    int T, D, L;
    cin>>T>>D>>L;
    if( T == 0 && D == 0 && L == 0) break;
    vector<int> A(T);
    cin>>A;

    int ans = 0;
    int counter = 0;
    for(int i=0;i<T;i++){
      int t = A[i];
      if(counter) ans++, counter--;
      if(t >= L) counter = D;
      
    }

    cout<<ans<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3580
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N = I()
dist = [[100]*(N+1) for _ in range(N+1)]  # 2点間の最短距離
edges = {}

for i in range(N-1):
    a,b = MI()
    dist[a][b] = 1
    dist[b][a] = 1
    edges[(a,b)] = i
    edges[(b,a)] = i

for i in range(1,N+1):
    dist[i][i] = 0

for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])

M = I()
A = []  # uとvを結ぶ経路上にある辺の集合
for _ in range(M):
    u,v = MI()
    B = set()
    while True:
        if dist[u][v] == 1:
            B.add(edges[(u,v)])
            break
        else:
            for i in range(1,N+1):
                if dist[u][i] == dist[u][v]-1 and dist[i][v] == 1:
                    B.add(edges[(i,v)])
                    v = i
                    break
    A.append(B)


def popcount(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c


# 包除原理

ans = 0
for i in range(2**M):
    C = set()
    for j in range(M):
        if (i >> j) & 1:
            C |= A[j]
    l = len(C)
    a = popcount(i)
    a %= 2
    ans += (-1)**a * 2**(N-1-l)

print(ans)


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

int main() {
  int x; cin >> x; 
  if(x==0) cout << 1 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3632
n, m, l = map(int, input().split(' '))

elements_a = []
elements_b = []

for i in range(n):
    elements_a.append(list(map(int, input().split(' '))))

for i in range(m):
    elements_b.append(list(map(int, input().split(' '))))

for ns in elements_a:
    for ls in range(l):
        result = 0
        for ms in range(m):
            result += ns[ms] * elements_b[ms][ls]
        if ls == l - 1:
            print(result)
        else:
            print(result, end =' ')



Measured memory_bytes: 6572
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

//ll mod = 1000000007;
ll mod = 998244353;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	//t %= mod;
	if (n % 2 == 1)t *= a;
	return t /*% mod*/;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
	vector<pair<ll,ll>> res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; 
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({ a, ex });
	}
	if (N != 1) res.push_back({ N, 1 });
	return res;
}


int main() {
	int n;
	cin >> n;
	vector<ll>num(100001);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		num[a]++;
		sum += a;
	}
	int q;
	cin >> q;
	vector<ll>ans(q);
	for (int i = 0; i < q; i++) {
		ll b, c;
		cin >> b >> c;
		sum -= num[b] * b;
		sum += num[b] * c;
		num[c] += num[b];
		num[b] = 0;
		ans[i] = sum;
	}
	for (int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using edge = struct {int to; ll cost;};

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
#define INF (1 << 29)


//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i <= n-3; i++) {
        if(s.substr(i, 3) == "ABC") ans++;
    }
    cout << ans << "\n";
}

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

Measured memory_bytes: 256