akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define eps 1e-9
#define nmax 200
#define f(c,a,b) for(int c=a; c<=b; c++)
#define pi acos(-1)

using namespace std;
typedef double db;
struct P{
    db x, y;
    P operator - (P a){ return (P){x-a.x, y-a.y}; }
    db dot(P a){ return a.x*x + a.y*y; }
    P operator * (db a) { return (P){a*x, a*y}; }
    P operator + (P a){ return (P){x+a.x, y+a.y}; }
    P operator / (db a) { return (P) {x/a, y/a}; }
    db times(P a){ return x*a.y-y*a.x; }
    db le() { return sqrt( x*x+y*y ); }
    db le2() { return x*x+y*y; }
    P rot90(){ return (P){-y,x}; }
    db rad(P a) { return atan2(times(a),dot(a)); }
    void pri(){ printf("%.10lf %.10lf\n", x, y); }
    void swap(P& a){
        db tx = x, ty = y;
        x = a.x;  y = a.y;
        a.x = tx; a.y = ty;
    }
    bool operator < (const P a) const { return (x==a.x)?(y<a.y):(x<a.x); } 
    bool operator == (const P a) const { return (x==a.x)&&(y==a.y); }
}po[nmax];

int sign(db x) { return (x<-eps) ? -1 : x>eps; }
db disLP(P p1, P p2, P p){ return abs( (p1-p).times(p2-p) ) / (p1-p2).le(); }

P projection(P a, P p, P q){ 
    P tl = q - p; 
    db ll = tl.le();  
    db k = (a-p).dot(tl)/ll/ll;  
    return (P){ p.x + k*tl.x, p.y + k*tl.y }; 
}

db disSP(P p1, P p2, P p){
    if((p1-p2).dot(p-p2) < eps) return (p-p2).le();
    if((p2-p1).dot(p-p1) < eps) return (p-p1).le();
    return disLP(p1, p2, p);
}

vector<P> cpCL(P c1, db r1, P p1, P q1){ 
    db dis = disLP(p1, q1, c1);
    dis = sqrt( r1*r1-dis*dis );
    P pj = projection(c1, p1, q1);
    P a1 = pj + (p1-q1) /(p1-q1).le() *dis;
    P a2 = pj + (q1-p1) /(q1-p1).le() *dis;
    return {a1, a2};
}

db interCT(P p1, db r1, P p2, P p3){
    P tp=p1; p1=p1-p1; p2=p2-tp; p3=p3-tp;
    int pd2 = sign(r1*r1-p2.le2()), pd3 = sign(r1*r1-p3.le2());
    vector <P> cp = cpCL(p1, r1, p2, p3);
    if(pd2>=0){
        if(pd3>=0) return p2.times(p3);
        return p2.times(cp[1]) + r1*r1*cp[1].rad(p3);
    }else{
        if(pd3>=0) return cp[0].times(p3) + r1*r1*p2.rad(cp[0]);
        if(disSP(p2,p3,p1) >= r1) {  return r1*r1*p2.rad(p3); }
        return r1*r1*p2.rad(cp[0])+cp[0].times(cp[1])+r1*r1*cp[1].rad(p3);
    }
}

int main(){
    //freopen("owo.in","r",stdin);
    int n;
    db r, ans=0;
    cin >> n >> r;
    f(i,0,n-1) scanf("%lf%lf", &po[i].x, &po[i].y);
    f(i,0,n-1) {
        db test=interCT((P){0,0}, r, po[i], po[(i+1)%n]);
        ans += test;
    }
    printf("%.12lf\n", ans/2);
    return 0;
}


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

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,m; cin>>n>>m;
	vector<string> g(n);
	for (int i=0; i<n; i++)
		cin>>g[i];
	for (int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			if(g[i][j]!='#') continue;
			bool ok=false;
			for (int k=0; k<4; k++) {
				int ii=i+dx[k], jj=j+dy[k];
				if(ii<0||ii>=n||jj<0||jj>=m) continue;
				if(g[ii][jj]=='#')
					ok=true;
			}
			if(!ok) {
				cout<<"No\n";
				return 0;
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
//AOJ 0000
//include
#include<cstdio>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<iostream>
 
//using namespace
using namespace std;
 
//define
 
//variable
short a, b;
 
//function
int main(){
  for(a = 1; a <= 9; a++)
    for(b = 1; b <= 9; b++)
      printf("%dx%d=%d\n", a, b, a * b);
  return 0;
}

Measured memory_bytes: 1096
#include <iostream>
#include <iomanip> // 追加
using namespace std;
 
int main(){
   int a, b;
   cin >> a >> b;
   cout << a/b << " " ;
   cout << a%b << " " << flush;
   // 小数点以下を6で固定
   cout << fixed << setprecision(6);
   // double に変換してから割る
   cout << (double)a/(double)b << endl;
}


Measured memory_bytes: 3260
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        N = N % 500;
        if(N > A){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,m,c;
  scanf("%d%d%d",&n,&m,&c);
  int *b=(int *)calloc(m,sizeof(int));
  int i,j;
  for(i=0;i<m;i++) scanf("%d",b+i);
  int ans=0;
  while(n--){
    int sum=0;
    for(i=0;i<m;i++){
      int a;
      scanf("%d",&a);
      sum+=a*b[i];
    }
    if(sum+c>0) ans++;
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;
    cin>>h>>w;
    int a[85][85],b[85][85];
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>b[i][j];
        }
    }
    bool dp[h+1][w+1][6401];
    dp[0][1][0]=true;
    dp[1][0][0]=true;
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            for(int k=0;k<6400;k++)
            {
                if(dp[i+1][j][k]||dp[i][j+1][k])
                {
                    int x=abs(k+a[i][j]-b[i][j]);
                    if(x<6400)
                    {
                        dp[i+1][j+1][x]=true;
                    }
                    x=abs(k+b[i][j]-a[i][j]);
                    if(x<6400)
                    {
                        dp[i+1][j+1][x]=true;
                    }

                }
            }
        }
    }

    int m=6400;
    for(int i=0;i<6400;i++)
    {
        if(dp[h][w][i])
        {
        	m=min(m,i);
        	break;
        }	
    }
    cout<<m<<endl;
    return 0;

}

Measured memory_bytes: 40832
#include <bits/stdc++.h>
using namespace std;
long long test,n,a[100001],s;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    //cin>>test;
    test=1;
    while (test--)
    {
       cin>>n;
       s=1;
       long long x=1e18,y=1e9;
       //cout<<x<<endl;
       for (int i=1;i<=n;i++) { cin>>a[i]; if (a[i]==0) { cout<<0<<endl; return 0; } }
       for (int i=1;i<=n;i++)
       if (sqrt(s)*sqrt(a[i])<=y)
       {
            if (s*a[i]<=x)
            {
                //cout<<sqrt(s)<<" "<<sqrt(a[i])<<endl;
                
                s*=a[i];
                //cout<<s-x<<endl;
            }
            else
            {
                cout<<-1<<endl; return 0;
            }
        }
        else
        {
           cout<<-1<<endl; return 0;
        }
        cout<<s<<endl;
    }
    
}    




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

int main(){
  int N;
  cin >> N;
  int A[N], x[N];
  x[0] = 0;
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < N; i++){
    x[0] += (1 - (i % 2) * 2) * A[i];
  }
  cout << x[0];
  for(int j = 1; j < N; j++){
    x[j] = (A[j - 1] - x[j - 1] / 2) * 2;
    cout << ' ' << x[j];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

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

    const auto ans = min(N * A, B);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
	int main(){
		int S,h,m,s,f;
		cin >> S;
		h=S/3600;
		f=S-(h*3600);
		m=f/60;
		s=f-(m*60);
		cout << h << ":" << m << ":" << s << endl;
	}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

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

    long long ans = 0;
    for (int i = 1; i <= k; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            for (int n = 1; n <= k; n++)
            {
                ans += gcd(i, gcd(j, n));
            }
        }
    }

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

Measured memory_bytes: 3584
S=input()

buf=list(S)

result=0

for i in range(len(S)):
    del buf[-1]
    if(len(buf)%2==0):
        tmp="".join(buf[0:int(len(buf)/2)])
        if "".join(buf).count(tmp)==2:
            result=len(buf)
            break

print(result)

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

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

using namespace std;

const int LIMIT = (1<<16), IINF = INT_MAX;

bool fin[LIMIT];
int N,dp[16][LIMIT];
string a,b;

int main(){
  while( cin >> N, N ){
    cin.ignore();
    getline(cin,a);
    getline(cin,b);

    if( a == b ) {
      puts("0");
      continue;
    }

    rep(i,N)rep(j,(1<<N)) dp[i][j] = IINF;
    rep(i,N) dp[i][0] = 0;

    rep(i,(1<<N)) {
      fin[i] = true;
      rep(j,N){
        if((i>>j) & 1) continue;
        if( a[j] != b[j] ) {
          fin[i] = false;
          break;
        }
      }
    }

    rep(state,(1<<N)){
      rep(cur,N){
        if( dp[cur][state] == IINF ) continue;
        rep(from,N){
          if( (state>>from) & 1 ) continue;
          rep(to,N){
            if( from == to ) continue;
            if( (state>>to) & 1 ) continue;
            if( !( a[from] == b[to] && a[to] == b[from] ) ) continue;
            int nstate = state|(1<<from)|(1<<to);
            if( fin[nstate] ) nstate = (1<<N)-1;
            dp[to][nstate] = min(dp[to][nstate],
                                 dp[cur][state] + abs(cur-from) + abs(from-to));
          }
        }
      }
    }

    int mini = IINF;
    rep(i,N) mini = min(mini,dp[i][(1<<N)-1]);
    cout << mini << endl;
  }
  return 0;
}

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

int main(){
  ll n;
  cin >>n;
  ll sum=0;
  map<ll,ll> mp;
  rep(i,n) {
    int a;
    cin >> a;
    mp[a] +=1;
    sum += a;
  }
  int q;
  cin >>q;
  rep(i,q){
    ll b,c;
    cin >> b >>c;
    sum-=b*mp[b];
    sum+=c*mp[b];
    mp[c]=mp[c] +mp[b];
    mp[b]=0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 9404
#include <stdio.h>
#define M 44

int memo[M];

int fib(int n){
    if(memo[n]!=0) return memo[n];
    if(n==0 || n==1) return memo[n]=1;
    else return memo[n]=fib(n-2)+fib(n-1);
}

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



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

#define ll long long
#define ar array

ll n, m, k, a[200000], b[200000], pr[200001][2];

bool ok(int x) {
	for (int i=0; i<=x; ++i) {
		if (i>n)
			break;
		if (x-i>m)
			continue;
		if (pr[i][0]+pr[x-i][1]<=k)
			return 1;
	}
	return 0;
}

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

	cin >> n >> m >> k;
	for (int i=0; i<n; ++i)
		cin >> a[i], pr[i+1][0]=a[i];
	for (int i=0; i<m; ++i)
		cin >> b[i], pr[i+1][1]=b[i];
	for (int i=1; i<=n; ++i)
		pr[i][0]+=pr[i-1][0];
	for (int i=1; i<=m; ++i)
		pr[i][1]+=pr[i-1][1];
	int l=0, r=n+m;
	while(l<r) {
		int mid=(l+r+1)/2;
		if (ok(mid))
			l=mid;
		else
			r=mid-1;
	}
	cout << l;
	return 0;
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


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

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int x; cin>>x;
	int m=x/100;
	
	if(x%100>m*5){
		cout<<"0\n";
	}
	else{
		cout<<1<<'\n';
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	char mes[101];
	char t;
	int a[100], b[100];
	int i, j;
	int diff;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		
		scanf("%s", mes);
		for (i = 0; i < n; i++){
			scanf("%d%d", &a[i], &b[i]);
		}
		for (i = n - 1; i >= 0; i--){
			a[i]--; b[i]--;
			 
			t = mes[a[i]];
			mes[a[i]] = mes[b[i]];
			mes[b[i]] = t;
//		printf("<%s>\n", mes);

			diff = b[i] - a[i];
			
			mes[a[i]] = ((mes[a[i]] - 'a' + diff + 26) % 26) + 'a';
			mes[b[i]] = ((mes[b[i]] - 'a' + diff + 26) % 26) + 'a';
		}
		
		printf("%s\n", mes);
	}
	
	return (0);
}

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

int main(){
    int n,t;
    cin>>n>>t;
    pair<int,int> p[n];
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        p[i]={a,b};
    }
    sort(p,p+n);
    int a[n],b[n];
    for(int i=0;i<n;i++){
        a[i]=p[i].first;
        b[i]=p[i].second;
    }
    ll dp[t+3030]={};
    for(int i=0;i<n;i++){
        for(int j=t+3029;j>=0;j--){
            if(0<=j-a[i]&&j-a[i]<t){
                dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
            }
        }
    }
    ll ans=0;
    for(int i=0;i<t+3030;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if (500*i+100*j+50*k)==X:
        ans+=1
print(ans)

Measured memory_bytes: 3060
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A 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 (LONG_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

#endif


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

    string S;  cin >> S;
    int N = S.size();
    
    vl sum(N, 0);
    if (S[0] == 'B') sum[0] = 1;
    else sum[0] = 0;
    FOR(i,1,N) {
        if (S[i] == 'B') sum[i] = sum[i - 1] + 1;
        else sum[i] = sum[i - 1];
    }

    ll ans = 0;
    REP(i,N) {
        if (S[i]=='W') ans += sum[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
///https://www.youtube.com/watch?v=-tJYN-eG1zk&list=RD-tJYN-eG1zk&start_radio=1
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vi vector<int>
#define vpii vector<pii>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue<int>
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
const int MXX = 1e5 + 5;

int a[MXX], b[MXX], c[MXX];
int main()
{

    FAST_IO;
    int n;
    cin>>n;
    map<int, int>mp1, mp2;
    int ans = 0;
    for(int i = 0; i<n; i++)cin>>a[i];
    for(int i = 0; i<n; i++)cin>>b[i], mp1[i+1] = b[i];
    for(int i = 0; i<n-1; i++)cin>>c[i], mp2[i + 1] = c[i];
    int pre = -1;
    for(int i = 0; i<n; i++)
    {
        if(i == 0)
        {
            ans+=mp1[a[i]];
        }
        else
        {
             ans+=mp1[a[i]];
             if(a[i-1] == a[i]-1)
             {
                // cout<<"ok"<<endl;
                 ans+=mp2[a[i-1]];
             }
             //cout<<a[i-1]<<" "<<a[i]<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# D - Walk and Teleport
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
dist=[]

for i in range(n-1):
    dist.append(x[i+1]-x[i])
ans=0
for i in range(len(dist)):
    if dist[i]*a<b:
        ans+=dist[i]*a
    else:
        ans+=b
print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,u,v,tot,lev[N],dep[N],lg[N],fa[N][20],head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
void dfs(int u,int p)
{
    dep[u]=dep[p]+1;fa[u][0]=p;
    for(int i=1;1<<i<=dep[p];i++)
        fa[u][i]=fa[fa[u][i-1]][i-1];
    lev[u]=true;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p) continue;
        dfs(v,u);lev[u]=false;
    }
}
int LCA(int u,int v)
{
    if(dep[u]<dep[v]) swap(u,v);
    while(dep[u]>dep[v]) u=fa[u][lg[dep[u]-dep[v]]];
    if(u==v) return u;
    for(int i=lg[dep[u]];i>=0;i--)
        if(fa[u][i]!=fa[v][i])
        u=fa[u][i],v=fa[v][i];
    return fa[u][0];
}
int DIS(int u,int v)
{
    return dep[u]+dep[v]-2*dep[LCA(u,v)];
}
int main()
{
    for(int i=1;i<N;i++) lg[i]=lg[i-1]+(1<<lg[i-1]==i);
    for(int i=1;i<N;i++) lg[i]--;
    scanf("%d%d%d",&n,&u,&v);
    for(int i=1;i<n;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        add(u,v);add(v,u);
    }
    dfs(1,0);
    int ans=0;
    for(int i=1;i<=n;i++)
        if(lev[i])
    {
        if(DIS(u,i)>=DIS(v,i)) continue;
        int len=DIS(v,i)-1;
        ans=max(ans,len);
    }
    cout<<ans;
}


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

int main(){
  int a[1000005];
  int s,i=2,ans=0,m;
  cin >> s;
  a[1]=s;
  while(1){
    if(a[i-1]%2==0){
      a[i]=a[i-1]/2;
    }else{
      a[i]=3*a[i-1]+1;
    }
    for(int j=1;j<i;j++){
      if(a[j]==a[i]){
	ans=1;
	m=i;
      }
    }
    if(ans==1){
      break;
    }
    i++;
  }
  cout << m << '\n';
  return 0;
}


Measured memory_bytes: 256
N, M = map(int,input().split())
X = list(map(int,input().split()))

if N >= M:
  print(0)
else:
  X.sort()
  dist = []
  
  for i in range(M-1):
    dist.append(X[i+1] - X[i])
    
  dist.sort()
  ans = 0
  
  for i in range(M-N):
    ans += dist[i]
    
  print(ans)

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[3],b[2];
    rep(i,0,3)cin >> a[i];
    rep(j,0,2)cin >> b[j];
    sort(a,a+3);
    sort(b,b+2);
    cout << a[0]+b[0]-50 << endl;
    return 0;
}

Measured memory_bytes: 3076
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = input().split()[0]

a = n.count("A")

b = n.count("B")

if a == 3 or b == 3:
    print("No")
else:
    print("Yes")














Measured memory_bytes: 38384
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#include <cstdio>
#define ll long long
using namespace std;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}
ll a,b,c,x,cnt;
int main()
{
	a=read(),b=read(),c=read(),x=read();
	for(register ll i=0; i<=a; i++)
		for(register ll j=0; j<=b; j++)
			for(register ll k=0; k<=c; k++)
			{
				if(i*500+j*100+k*50==x) cnt++;
				if(i*500+j*100+k*50>x) break;
			}
	printf("%lld\n",cnt);		
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N,K,C;
	cin >> N >> K >> C;
	string S;
	cin >> S;
	string R = S;
	C++;
	reverse(R.begin(), R.end());
	vector<int>Str(K);
	{
		int tmp = -C;
		for (int n = 0; n < K; ++n) {
			tmp += C;
			while (true) {
				if ('o' == S[tmp]) {
					Str[n] = tmp; 
					//cout << tmp << endl;
					break;
				}
				else {
					tmp++;
				}
			}
		}
	}
	vector<int>End(K);
	{
		int tmp = -C;
		for (int n = 0; n < K; ++n) {
			tmp += C;
			while (true) {
				if ('o' == R[tmp]) {
					End[n] = tmp;
					//cout << tmp << endl;
					break;
				}
				else {
					tmp++;
				}
			}
		}
	}
	for (int n = 0; n < K; ++n) {
		if (Str[n]  == (N-1) - End[K - n-1]) {
			cout << Str[n] + 1<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 5188
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=998244353;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    vector<vector<ll>> dp(3001,vector<ll>(3001));
    dp[a][b]=1;
    for(ll k=1;k<=(c+d-a-b);k++){
        for(ll i=a;i<=a+k;i++){
            ll j=k-(i-a)+b;
            if(i>c || j>d) continue;
            if(i>=a+1 && j>=b+1){
                dp[i][j]+=dp[i-1][j]*j%mod;
                dp[i][j]%=mod;
                dp[i][j]+=dp[i][j-1]*i%mod;
                dp[i][j]%=mod;
                ll add=((dp[i-1][j-1]*(i-1))%mod)*(j-1)%mod;
                dp[i][j]+=mod-add;
                dp[i][j]%=mod;
            }
            else if(i>=a+1){
                dp[i][j]+=dp[i-1][j]*j%mod;
                dp[i][j]%=mod;
            }
            else if(j>=b+1){
                dp[i][j]+=dp[i][j-1]*i%mod;
                dp[i][j]%=mod;
            }
            
            //cout << i << " " << j << " " << dp[i][j] << endl;
        }
    }
    cout << dp[c][d] << endl;
} 

Measured memory_bytes: 73744
#include<stdio.h>
#include<stdlib.h>

int sortfnc(const void *a,const void *b){
    if(*(long long*)a == *(long long*)b){return 0;}
    if(*(long long*)a > *(long long*)b){return -1;}
    return 1;
}

int main(void){
	long long n,a[524288],r = 0,i;
	scanf("%lld",&n);
	for(i = 0;i < 3*n;i++){scanf("%lld",&a[i]);}
	qsort(a,3*n,sizeof(long long),sortfnc);
	for(i = 1;i < 2*n;i+=2){r+=a[i];}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 5884
fun main(args: Array<String>) = asakatsu0404b()

fun asakatsu0404b() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toInt() }

    val sum = LongArray(100010)

    aList.forEach { (it - 1..it + 1).forEach { sum[it + 1]++ } }

    val answer = sum.max()!!

    println(answer)
}


Measured memory_bytes: 56108
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    Senky_Bansal
    IIIT_ALLAHABAD
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>>v;
    for(int i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        v.pb(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    ll ans=0;
    ll fg=0;
    for(int i=0;i<v.size();i++)
    {
        if(fg+v[i].second>=m)
        {
            ans+=(m-fg)*v[i].first;
            cout<<ans;
            return 0;
        }
        else
        {
         ans+=v[i].first*v[i].second;
         fg+=v[i].second;
        }
    }
}


Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>
#include <fstream>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ofstream w_file("abc144_e.txt", ios::app);

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N), F(N), as(N+1, 0);
    Rep (i, N) {
        cin >> A[i];
        as[i+1] = as[i] + A[i];
    }
    Rep (i, N) {
        cin >> F[i];
    }

    sort(A.begin(), A.end());
    sort(F.begin(), F.end());

    ll ok = 1e18;
    ll ng = -1;

    while (abs(ok-ng) > 1) {
        ll mid = (ok+ng) / 2;
        vector<ll> check(N);
        Rep (i, N) {
            check[i] = mid / F[i];
        }
        sort(check.begin(), check.end());
        ll tmp = 0;
        Rep (i, N) {
            tmp += max((ll)0, A[i] - check[i]);
        }

        w_file << mid << " " << tmp << "\n";
        if (tmp <= K) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;
}

Measured memory_bytes: 6528
n,m,k = map(int,input().split())
par = [-1]*n
num = [0]*n
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    if x==y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)

def size(x):
    return -par[find(x)]

for i in range(m):
    a,b = map(int,input().split())
    unite(a-1, b-1)
    num[a-1] += 1
    num[b-1] += 1

edge = [[] for i in range(n)]

for i in range(k):
    c,d = map(int,input().split())
    edge[c-1].append(d-1)
    edge[d-1].append(c-1)

for i in range(n):
    cnt = size(i) - num[i] - 1
    for e in edge[i]:
        if same(e, i):
            cnt -= 1
    print(cnt, end=' ')

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

const int mod = 1e9+7;
int main()
{
	string t; 
	cin >> n >> s >> t;
	rep(i,n){
		cout << s[i] << t[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from operator import mul
from functools import reduce
import math
mod=10**9+7

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

def combinations_count(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))%mod



input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

n,k=map(int,input().split())
l=n-k
for i in range(1,k+1):
    if l+1<i or k<i:
        ans=0
    else:
        ans=(combinations_count(l+1,i)*combinations_count(k-1,i-1))%mod
    print(ans)


Measured memory_bytes: 3944
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n)
{
	KAKA
	vector<ll> ar(n);
	vector<ll> x(n);
	ll xo = 0;
	pragi(0,n)
	{
		cin>>ar[i];
		xo ^= ar[i];
	}
	pragi(0,n)
	{
		x[i] = ar[i] ^ xo;
	}
	pragi(0,n)
	{
		cout<<x[i]<<" ";
	}
	cout<<"\n";
}
int main()
{
	KAKA
	ll n;
	cin>>n;
	Compute(n);
}

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

#define f first
#define s second
#define p pair<int,int>
#define ll long long
#define db double
#define db double

const int maxn=1e6+5;
const int inf=1e9;

ll n,m,k,flag,ok,a[maxn],b[maxn],ans,sum;
string s;

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    string s;
    cin>>s;
    string t=s;
    reverse(s.begin(),s.end());
    if(s==t)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin

#s = 'vanceknowledgetoad'
#p = 'advance'
s = stdin.readline().rstrip()
p = stdin.readline().rstrip()

s = s * 2
#print(s)
#print(len(p))
cnt_match_inrow=0
p_index = 0
match_start_index = 0
match_start_buf=0
s_index = -1
#だめ　無限ループ
while s_index < len(s)-1:
  s_index+=1
  if s[s_index] == p[p_index]:
    if p_index == 0:
      match_start_index = s_index
    p_index += 1
    cnt_match_inrow += 1
    if cnt_match_inrow == len(p):
      print('Yes')
      break
  else:
    p_index = 0
    s_index -= cnt_match_inrow
    cnt_match_inrow = 0
else:
  print('No')


Measured memory_bytes: 5568
import sys


def alg_combination_mod(n, r, mod):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i) % mod
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i) % mod
        return denominator * pow(molecule, mod - 2, mod) % mod


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, y = list(map(int, readline().split()))
    if (x + y) % 3 == 0:
        t = (x + y) // 3
        if x >= 0 and y >= 0:
            for i in range(t + 1):
                if i + 2 * (t - i) == x and (t - i) + i * 2 == y:
                    print(alg_combination_mod(t, i, mod))
                    exit()
            print(0)
        else:
            print(0)
    else:
        print(0)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38768
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int num(int y, int m, int d) {
	int ans = 0;
	int year = (20 + 19) * 5;
	int year_div3 = 20 * 10;
	
	REP(i, 1, y) {
		ans += (i % 3 == 0) ? year_div3 : year;
	}
	REP(i, 1, m) {
		if (y % 3 != 0 && i % 2 == 0) {
			ans += 19;
		}
		else {
			ans += 20;
		}
	}
	ans += d;

	return ans;
}
int main() {
	int n;

	cin >> n;
	REP(j, 0, n) {
		int Y, M, D;
		cin >> Y >> M >> D;

		cout << num(1000, 1, 1) - num(Y, M, D) << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>
#include <string.h>
int main(void){
	int N,M,Q,i,j,k;
	scanf("%d%d%d",&N,&M,&Q);
	int l,r,p,q,x[501][501]={0},sum[501][501]={0},ans;
	for(i=0;i<M;i++){
		scanf("%d%d",&l,&r);
		x[l][r]++;
	}
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++)sum[i][j] = sum[i][j-1] + x[i][j];
	}
	
	for(i=0;i<Q;i++){
		scanf("%d%d",&p,&q);
		ans = 0;
		for(j=p;j<=q;j++)ans += sum[j][q]-sum[j][p-1];
		printf("%d\n",ans);
	}
	
	
	return 0;
}

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

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


Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	double a,b,p,q,r;
	cin>>a>>b>>p>>q>>r;
	cout<<fixed<<setprecision(12);
	cout<<b+(b*p-(b-a)*q)/(q+r)<<endl;
	return 0;
}


Measured memory_bytes: 3292
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 Scanner scn=new Scanner(System.in);
		 int n=scn.nextInt();
		 int digit=1,count=0;
		 for(int i=1;i<=n;i++) {
			 if(i%10==0){
				 int tmp=0,x=i;
				 while(x!=0) {
					 x=x/10;
					 tmp++;
				 }
				 digit=tmp;
			 }
			 if(digit%2!=0) {
				// System.out.println(i);
					 count++;				 
			 }
		 }
		 System.out.println(count);
	}

}


Measured memory_bytes: 21844
from math import ceil
from bisect import bisect_left


def solve(n, h):
    a = []
    b = []

    for i in range(n):
        ai, bi = map(int, input().split())
        a.append(ai)
        b.append(bi)

    amax = max(a)
    b.sort()

    if n == 1:
        ans = ceil((h-b[n-1])/amax)+1

    else:
        over_amax = b[bisect_left(b, amax):]
        if h <= sum(over_amax):
            for j in range(n-1, -1, -1):
                h -= b[j]
                if h <= 0:
                    ans = n-j
                    break

        else:
            ans = ceil((h - sum(over_amax)) / amax) + len(over_amax)

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))


Measured memory_bytes: 11864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> cnt(10, vector<ll>(10, 0));

  FOR(i, 1, n + 1) {
    string s = to_string(i);
    ll a = s[0] - '0';
    ll b = s[SZ(s) - 1] - '0';
    if (a == 0 || b == 0) {
      continue;
    }
    cnt[a][b]++;
  }
  ll ans = 0;
  FOR(i, 1, 10) FOR(j, 1, 10) { ans += cnt[i][j] * cnt[j][i]; }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}

struct unionfind{
  vector<int> par;
  vector<int> size;
  void begin(int n){
    par.resize(n,-1);
    size.resize(n,1);
  }
  int find(int x){
    if(par[x]==-1)return x;
    par[x]=find(par[x]);
    return par[x];
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    par[x]=y;
    size[y]+=size[x];
    return;
  }
};

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

  int n,k,l;cin >> n >> k >> l;
  unionfind tr,ro;
  tr.begin(n);
  ro.begin(n);
  rep(i,k){
    int a,b;cin >> a >> b;
    ro.unite(a-1,b-1);
  }rep(i,l){
    int a,b;cin >> a >> b;
    tr.unite(a-1,b-1);
  }
  
  /*
  電車での連結状態と車での連結状態が得られた
  ある点からの根っこが電車/車で同じなら良い
  てことは解けた…！！
  */
  map<p,int> ans;
  rep(i,n){
    ans[p(tr.find(i),ro.find(i))]++;
  }
  rep(i,n)cout << ans[p(tr.find(i),ro.find(i))] << '\n';
}

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

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

 int main() {
   int N, a;
   cin >> N;
   map<string, int> LB;

   rep(i, N) {
     cin >> a;
     if (a <= 399) LB["a"]++;
     else if (a <= 799) LB["b"]++;
     else if (a <= 1199) LB["c"]++;
     else if (a <= 1599) LB["d"]++;
     else if (a <= 1999) LB["e"]++;
     else if (a <= 2399) LB["f"]++;
     else if (a <= 2799) LB["g"]++;
     else if (a <= 3199) LB["h"]++;
     else LB["x"]++;
   }

   int min_ans = 0, max_ans = 0;

   for (auto p: LB) {
     if (p.first != "x" && p.second > 0) {
       min_ans++;
       max_ans++;
     }
     else if (p.first == "x") {
       max_ans += p.second;
       min_ans = max(min_ans, 1);
     }
   }

   cout << min_ans << " " << max_ans << endl;
 }


Measured memory_bytes: 256
from itertools import product
import math

d, g = map(int, input().split())
ps = []
cs = []

for i in range(d):
    pi, ci = map(int, input().split())
    ps.append(pi)
    cs.append(ci)

min_count = 10000000
for pro in product([0,1,2], repeat=d):
    if len([_ for _ in pro if _ == 2]) <= 1:
        tmp_count = 0
        tmp_total = 0
        for i in range(len(pro)):
            if pro[i] == 1:
                tmp_count += ps[i]
                tmp_total += ps[i] * (i+1) * 100 + cs[i]
        if tmp_total >= g:
            min_count = min(min_count, tmp_count)
            continue
        elif 2 in pro and ps[pro.index(2)] * (pro.index(2)+1) * 100 >= g-tmp_total:
            tmp_count += -(-(g-tmp_total) // ((pro.index(2)+1) * 100))
            tmp_total += tmp_count * (pro.index(2)+1) * 100
            min_count = min(min_count, tmp_count)
            continue

print(min_count)



Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

vector<p>rinsetu[100];
bool g[100];
int mincost[100][101];
int main(){
    int a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f,a|b|c|d|e|f){
	for(int h=0;h<a;h++){
	    rinsetu[h].clear();
	    g[h]=false;
	    }
	for(int h=0;h<c;h++){
	    int i;scanf("%d",&i);
	    g[i]=true;
	    }
	    for(int h=0;h<d;h++){
		int i,j,k;scanf("%d%d%d",&i,&j,&k);
		rinsetu[i].push_back(p(k,j));
		rinsetu[j].push_back(p(k,i));
		}
	memset(mincost,0x3f,sizeof(mincost));
	mincost[e][0]=0;
	priority_queue<P,vector<P>,greater<P>>Q;
	Q.push(P(0,p(e,0)));
	while(Q.size()){
	    P t=Q.top();Q.pop();
	    int cost=t.first,to=t.second.first,time=t.second.second;
	    if(mincost[to][time]<cost)continue;
	    if(g[to]){
		for(int i=0;i<time;i++){
		    if(mincost[to][i]>cost+time-i){
			mincost[to][i]=cost+time-i;
			Q.push(P(mincost[to][i],p(to,i)));
			}
		    }
		}
	   for(p i:rinsetu[to]){
	      int k=time+i.first;
	      if(k>b)continue;
	      if(mincost[i.second][k]>cost+i.first){
		  mincost[i.second][k]=cost+i.first;
		  Q.push(P(cost+i.first,p(i.second,k)));
		  }
	       }	
	    }
	  int MIN=1<<29;
	   for(int i=0;i<=b;i++)MIN=min(MIN,mincost[f][i]);
	   if(MIN==1<<29)puts("Help!");
	   else cout<<MIN<<endl; 
	}
    }

Measured memory_bytes: 3320
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, R);
    IN(ll, C);
    IN(ll, K);
    vi r(K), c(K), v(K);
    REP(i, K)
    {
        cin >> r[i] >> c[i] >> v[i];
    }
    vvi V(R + 1, vi(C + 1, 0));
    REP(i, K)
    {
        V[r[i]][c[i]] = v[i];
    }
    vector<vvi> dp(R + 1, vvi(C + 1, vi(5, 0)));
    REP1(i, R)
    {
        REP1(j, C)
        {
            REP1(k, 4)
            {
                dp[i][j][k] = max({dp[i - 1][j][k], dp[i][j - 1][k], dp[i][j][k - 1]});
                if (V[i][j] > 0 and k >= 2)
                {
                    if (k == 2)
                    {
                        dp[i][j][k] = max({dp[i][j][k], dp[i - 1][j][4] + V[i][j], dp[i][j - 1][k - 1] + V[i][j]});
                    }
                    else
                    {
                        dp[i][j][k] = max({dp[i][j][k], dp[i][j - 1][k - 1] + V[i][j]});
                    }
                }
            }
            // DUMP(i);
            // DUMP(j);
            // DUMP(dp);
        }
    }
    // DUMP(dp);
    OUT(dp[R][C][4]);
}

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

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

    double ans = 0;
    REP(i,N){
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") ans += x;
        else ans += 380000 * x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;




int main(void) {
  string s;
  cin >> s;
  
  
  ll Q;
  cin >> Q;
  ll r=0;
  vector<char> left, right;
  
  for(ll _=0; _<Q; _++) {
    ll t;
    cin >> t;
    if(t==1) {
      r=1-r;
    }else if(t==2) {
      ll f;
      char c;
      cin >> f >> c;
      
      if(f==1) {
        if(r==0) left.push_back(c);
        else     right.push_back(c);
      }else if(f==2) {
        if(r==0) right.push_back(c);
        else     left.push_back(c);
      }
      
    }
    
  }
  
  
  
  
  
  if(r==0) {
    for(ll i=(ll)left.size()-1; i>=0; i--) {
      cout << left[i];
    }
    cout << s;
    for(ll i=0; i<right.size(); i++) {
      cout << right[i];
    }
    pt("");
    
  }else {
    for(ll i=(ll)right.size()-1; i>=0; i--) {
      cout << right[i];
    }
    for(ll i=(ll)s.size()-1; i>=0; i--) {
      cout << s[i];
    }
    for(ll i=0; i<left.size(); i++) {
      cout << left[i];
    }
    pt("");
  }
  
  
  
}






Measured memory_bytes: 1024
int main() {
	int n;
	int cnt1 = 0;
	int cnt2 = 0;
	scanf("%d", &n);
	while(n>=500){
		n -= 500;
		cnt1++;
	}
	while (n >= 5) {
		n -= 5;
		cnt2++;
	}
	int sum = 0;
	sum = 1000 * cnt1 + 5 * cnt2;
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    ll n, a , b, c;
    cin >> n >> a >> b;
    c = min(a - 1 + (b - (a - 1)) / 2, n - b + (n - (a + (n - b))) / 2 + (n - (a + (n - b))) % 2);
    c = min(c, min(b - 1, n - a));
    if ((b - a) % 2 == 0)
        cout << min((b - a) / 2, c) << endl;
    else
        cout << c << endl;

    return 0;
}

// 1000000000000000000
// 999999999999999999

Measured memory_bytes: 256